【发布时间】:2017-07-05 02:04:49
【问题描述】:
这是我的 .json 文件
数组 ( [0] => 数组 ( [id] => 1 [名称] => 冰雕 [价格] => 12.5 [标签] => 数组 ( [0] => 冷 [1] => 冰 )
[dimensions] => Array
(
[length] => 7
[width] => 12
[height] => 9.5
)
[warehouselocation] => Array
(
[latitude] => -78.75
[longitude] => 20.4
)
)
[1] => Array
(
[id] => 2
[name] => A blue mouse
[price] => 25.5
[tags] => Array
(
[0] => cold
[1] => ice
)
[dimensions] => Array
(
[length] => 3.1
[width] => 1
[height] => 1
)
[warehouselocation] => Array
(
[latitude] => 54.4
[longitude] => -32.7
)
)
[2] => Array
(
[id] => 2
[name] => A blue mouse
[price] => 25.5
[dimensions] => Array
(
[length] => 3.1
[width] => 1
[height] => 1
)
[warehouselocation] => Array
(
[latitude] => 54.4
[longitude] => -32.7
)
)
[3] => Array
(
[id] => 3
[name] => A Chainsmoker
[price] => 99.5
[tags] => Array
(
[0] => king
[1] => wils
)
[dimensions] => Array
(
[length] => 7.1
[width] => 25
[height] => 7
)
[warehouselocation] => Array
(
[latitude] => 54.4
[longitude] => -32.7
)
)
) 这里我只想显示大于 15.0 的数据价格。 如何在 Laravel
中使用 foreach 进行显示`$ProductList=file_get_contents('C:\xampp\htdocs\Laravel\resources\data\ProductList.json');
$data=json_decode($ProductList,true);
//print_r($data);
foreach($data as $key => $value) {
if ($key == 'price' && $value > 15)
echo $value;
}
print_r($value);
`
【问题讨论】:
-
我以 $ProductList=file_get_contents('C:\xampp\htdocs\Laravel\resources\data\ProductList.json'); 访问文件$data=json_decode($ProductList,true);打印_r($数据);这是我直接以数组格式显示整个文件,但现在我只想显示价格大于 15.0
标签: laravel