-2

$var 的正确语法是什么?我想用它作为尚未存在的数组单元的指定(//代码中的方式):

$array = array (
    array("folder" => "november", "name" => "1.jpg"),
    array("folder" => "december", "name" => "1.jpg")
);
$var = "$picture['folder']"; // how to make it not a string value and use it in foreach cycle

foreach ($array as $picture) { // only here comes subarray
    echo $var;
    echo '<br>';
}

/* should be
november
december
*/

PS这是一个简单的图库日历任务,我们回显图像路径...

4

1 回答 1

0

我还是不知道你在找什么……???

但这就是你所拥有的一切:

$array = array(
       array("folder" => "november", "name" => "1.jpg"),
       array("folder" => "december", "name" => "1.jpg")
   );

print "<pre>"; 

foreach ($array as $index => $subArray)
{
   print "\$index = $index   <br/>";
   print "\$index[$index]['folder'] = {$array[$index]['folder']} = {$subArray['folder']}  <br/>"; 
   print "\$index[$index]['folder'] = {$array[$index]['name']}   = {$subArray['name']}    <br/>"; 
   print "<br/>";
}   

print "</pre>"; 


/*

$index = 0   
$index[0]['folder'] = november = november  
$index[0]['folder'] = 1.jpg   = 1.jpg    

$index = 1   
$index[1]['folder'] = december = december  
$index[1]['folder'] = 1.jpg   = 1.jpg    


*/
于 2013-11-09T13:48:34.430 回答