jmu jmu - 15 days ago 4
PHP Question

how to read string in Array ([2622232] => [] => apple ) PHP

I am trying to read string in session array.

Here is the code I entered

$fruit_type
into my session:($number is 2622232 here)

$_SESSION['fruit'][$number]=$fruit_type;


When I used
print_r($_SESSION['fruit'])
, I get the following array:

Array ( [2622232] => [] => apple )


My question is how can I get the string "apple"? My editor give me error message when I tried to use
$_SESSION['fruit'][$number][]
to read string.

Any idea about my situation?

Answer

The only way to get that print_r() output is with an empty string as key [''], so you need to find where you do that and fix it. However you can access it:

echo $_SESSION['fruit'][2622232][''];