来自PHP的PHP PAR数组
我知道也有类似的问题,我用其中的一些问题走到了这一步,但有一个问题。我有一个php文件,其中包含如下数组:来自PHP的PHP PAR数组,php,arrays,parsing,Php,Arrays,Parsing,我知道也有类似的问题,我用其中的一些问题走到了这一步,但有一个问题。我有一个php文件,其中包含如下数组: <?php error_reporting(0); $items = array( array( "name" => "Shirts", "size" => "100", "country" => "United States", "color" =
<?php
error_reporting(0);
$items = array(
array( "name" => "Shirts",
"size" => "100",
"country" => "United States",
"color" => "red",
"sleeve"=>"short",
"neck" =>"crew",
),
执行脚本时,将显示阵列的完整列表。不知道该怎么做才能得到需要的。
谢谢这正是您的阵列结构 尝试将阵列重建为以下结构
$items = array(
'Shirts' => array(
array(
'size' => 100,
'country' => 'United States',
'color' => 'red',
'sleeve' => 'short',
'neck' => 'crew'
),
array(
'size' => 120,
'country' => 'United States',
'color' => 'green',
'sleeve' => 'short',
'neck' => 'crew'
),
array(
'size' => 140,
'country' => 'United States',
'color' => 'blue',
'sleeve' => 'short',
'neck' => 'crew'
)
)
);
if(count($items['Shirts'])){
foreach($items['Shirts'] AS $index => $shirt_data){
$color = $shirt_data['color'];
$sleeve = $shirt_data['sleeve'];
}
}
$val['items']['Shirts']
->$items
?!很抱歉,我不明白您的意思。您从包含的if中向我们显示的数组具有变量名:$items
,因此请像这样使用它,例如foreach($items as$result)
谢谢,工作方式与我所需的一样。
$items = array(
'Shirts' => array(
array(
'size' => 100,
'country' => 'United States',
'color' => 'red',
'sleeve' => 'short',
'neck' => 'crew'
),
array(
'size' => 120,
'country' => 'United States',
'color' => 'green',
'sleeve' => 'short',
'neck' => 'crew'
),
array(
'size' => 140,
'country' => 'United States',
'color' => 'blue',
'sleeve' => 'short',
'neck' => 'crew'
)
)
);
if(count($items['Shirts'])){
foreach($items['Shirts'] AS $index => $shirt_data){
$color = $shirt_data['color'];
$sleeve = $shirt_data['sleeve'];
}
}