如何从以下 foreach 代码中通过键名获取特定数据.
how to get specific data by key name from the following foreach code.
<?php
foreach ($_SESSION as $key=>$val)
echo $key." ".$val."<br/>";
?>
数组看起来像这样想要获取特定键的值.
array is look like this want to get value of specific key.
{"name":"bedroom","rent":"sale","props":"","leases":""}
我尝试了以下代码但不起作用
i have tried following code but doesn't work
echo "checking key sep. ".$key[rent];
如果可能,我可以通过姓名或租金等关键名称访问.
if possible i can access by key name like name or rent.
格式为JSON,需要先使用json_decode()
The format is in JSON , you need to decode it first by using json_decode()
这样的东西...
$yourJSON = '{"name":"bedroom","rent":"sale","props":"","leases":""}';
$yourarray = json_decode($yourJSON,1);
然后您可以像这样使用 foreach 构造来循环 $yourarray.
You can then loop the $yourarray using the foreach construct like this.
foreach($yourarray as $key=>$val)
{
echo $key." ".$val."<br/>";
}
用于从中检索特定密钥..
For retrieving a specific key from it..
echo $yourarray['rent']; //"prints" sale
这篇关于php - foreach - 通过键名获取具体数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
MySQLi准备好的语句&foreach 循环MySQLi prepared statement amp; foreach loop(MySQLi准备好的语句amp;foreach 循环)
mysqli_insert_id() 是从整个服务器还是从同一用户获Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是从整个服务器还是从同一用户获取记录?)
PHP MySQLi 无法识别登录信息PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 无法识别登录信息)
mysqli_select_db() 需要 2 个参数mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 个参数)
Php mysql pdo 查询:用查询结果填充变量Php mysql pdo query: fill up variable with query result(Php mysql pdo 查询:用查询结果填充变量)
MySQLI 28000/1045 用户“root"@“localhost"的访问MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用户“root@“localhost的访问被拒绝)