php 循环取json中"orderTitle" :“1234”
时间: 2023-05-14 13:04:30 浏览: 69
可以使用以下代码来循环取出json中"orderTitle"为"1234"的数据:
$json = '{
"orders": [
{
"orderTitle": "1234",
"orderPrice": "100"
},
{
"orderTitle": "5678",
"orderPrice": "200"
},
{
"orderTitle": "1234",
"orderPrice": "150"
}
]
}';
$data = json_decode($json, true);
foreach ($data['orders'] as $order) {
if ($order['orderTitle'] == '1234') {
echo $order['orderPrice'] . '<br>';
}
}
这段代码会输出:
100
150
相关问题
php 循环取json中"orderTitle" :“1234”,取"orderTitle" 对应的键值
您可以使用以下代码来循环取出 JSON 中的 "orderTitle" 对应的键值:
$json = '{"orders":[{"orderTitle":"1234","orderDate":"2021-01-01"},{"orderTitle":"5678","orderDate":"2021-01-02"}]}';
$data = json_decode($json, true);
foreach ($data['orders'] as $order) {
echo $order['orderTitle'] . "\n";
}
这将输出:
1234
5678
请注意,这是 PHP 代码,您需要在 PHP 环境中运行它才能得到正确的结果。
php 循环取json中"orderTitle"
可以使用以下代码来循环取出json中的"orderTitle":
$json = '{
"orders": [
{
"orderTitle": "Order 1",
"orderNumber": "12345"
},
{
"orderTitle": "Order 2",
"orderNumber": "67890"
}
]
}';
$data = json_decode($json, true);
foreach ($data['orders'] as $order) {
echo $order['orderTitle'] . "\n";
}
输出结果为:
Order 1
Order 2
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)