这些PHP数组是什么意思?

时间:2013-08-15 10:37:51

标签: php arrays for-loop

有人可以向我解释下面for循环 中代码 每行 意味着什么办?

$var = array();
$ship = $_POST['product'];
$amount = count( $ship );

for ($i = 0; $i < $amount; $i++){


$var[$i]['product']

$ship[$i]

$var[$i]['name'] = $ship[$i];

echo $var;


}

谢谢!

1 个答案:

答案 0 :(得分:4)

只是因为它很有趣:

$var = array(); // create an array
$ship = $_POST['product']; //store 'product' from HTTP POST in .. what, ship?
$amount = count($ship); //it seems our ship as an array, let's figure out how much items it contains
for ($i = 0; $i < $amount; $i++) //let's start from element #0, and do it until all ship's elements will be passed
{ // opening bracket
  $var[$i]['product']; //do nothing? ; was skipped
  $ship[$i]; //do nothing? ; was skipped
  $var[$i]['name'] = $ship[$i]; //store whole 'ship' in 'name' index of 'var'
  echo $var; //tada: echoing var
} // closing bracket