skip to Main Content

I’m trying to access a single time result stored in $_SESSION[‘pickup_time’]

When I ran this to find out what’s in the variable

echo var_dump($_SESSION['pickup_time']) . "<br />";

This is the results I’m getting

string(8) "07:30:00"
string(8) "07:30:00"

How do I put the value 07:30 in a variable called $userpickuptime?

Updated for @tebe

            echo '<pre>' , var_dump($_SESSION['pickup_time']) , '</pre>';
            // init the var
            $userpickuptime = $_SESSION['pickup_time'];
            // and echo it
            echo $userpickuptime;

Results as below

string(8) "06:30:00"
06:30:00
string(8) "06:30:00"
06:30:00

Eventually I only want 06:30 in $userpickuptime

Updated for @bobi

            $userpickuptime = $_SESSION['pickup_time'];
            echo $userpickuptime;

The results is

06:30:0006:30:00

What do I do so that only 06:30:00 is in $userpickuptime ?

This system isn’t developed by me. I’m not sure why it is executed twice 🙁

2

Answers


  1. It looks like your code is simply executed twice. That’s the reason for the timestamp echoed two times.

    It is also not required to echo a var_dump, since var_dump itself has no return value. So, it’s enough to do it this way.

    var_dump($_SESSION['pickup_time']);
    

    And regarding your question, how to put a value in a variable, you can do this like so.

    // init the var
    $userpickuptime = $_SESSION['pickup_time'];
    
    // and echo it
    echo $userpickuptime;
    
    Login or Signup to reply.
  2. since result from $_SESSION[‘pickup_time’] is 06:30:0006:30:00 you have 2 options

    1. fix $_SESSION[‘pickup_time’] to return correct string time

    2. split string and get the part you want

    example

    $time = '06:30:0006:30:00';
    $split_time = mb_substr($time, 0, 8);
    
    echo $split_time;
    

    output

    06:30:00
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search