此代码构建一个数组:
$size = sizeof($include_quotes);
for ($i=0; $i<$size; $i++) {
$quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
if (is_array($quotes)) $quotes_array[] = $quotes;
}
}
如果我
print_r($quotes_array);
我得到以下信息:
Array ( [0] => Array ( [id] => advshipper [methods] => Array ( [0] => Array ( [id] => 1-0-0 [title] => Trade Shipping [cost] => 20 [icon] => [shipping_ts] => [quote_i] => 0 ) [1] => Array ( [id] => 2-0-0 [title] => 1-2 working days [cost] => 3.2916666666667 [icon] => [shipping_ts] => [quote_i] => 1 ) [2] => Array ( [id] => 4-0-0 [title] => 2-3 working days [cost] => 2.4916666666667 [icon] => [shipping_ts] => [quote_i] => 2 ) [3] => Array ( [id] => 8-0-0 [title] => Click & Collect [cost] => 0 [icon] => [shipping_ts] => [quote_i] => 3 ) ) [module] => Shipping [tax] => 20 ) )
在某些情况下,我只希望将字段0
中的数据传递到代码的下一部分。但是,使用
$sliced_quotes_array = array_slice($quotes_array,0,1);
仍然返回所有结果。
获得公正的正确方法是什么:
Array ( [0] => Array ( [id] => advshipper [methods] => Array ( [0] => Array ( [id] => 1-0-0 [title] => Trade Shipping [cost] => 20 [icon] => [shipping_ts] => [quote_i] => 0 )
非常感谢任何帮助,因为我尝试了许多不同的方法,但还没有运气。
使用以下仍然返回相同的结果
$testarray = array(0 => $quotes_array[0]);
print_r($testarray);