从会话数组中回显索引

I have a session that stores an array.

Let's say, my sessions are cars and music that each stores the following:

<?php
$_Session['cars'] =array("Volvo","BMW","Toyota");
$_Session['music'] = array("Beatles", "Carpenters", "Sting");
?>

Now, how can I echo the following based on my sessions:

BMW Sting

Thanks in advance. :)

You try with array index value. i.e session array index value

<?php
session_start(); // To enable session to current page
$_SESSION['cars'] =array("Volvo","BMW","Toyota");
$_SESSION['music'] = array("Beatles", "Carpenters", "Sting");
echo $_SESSION['cars'][1]; // will print "BMW"
echo $_SESSION['music'][2]; // will print "Sting"
?>

Add session_start() at the top of your code, then

echo $_SESSION['cars'][1];
echo $_SESSION['music'][2];

Note the case of $_SESSION - your snippet uses the wrong case and won't store data in the $_SESSION array