我需要什么:
这是我的代码
$元数据= json_decode($元数据,TRUE);
它输出我的数组
Array
(
[name] => Yogender
[email] => yogensingh@
[designation] => Business Manager
[website] =>
[phone] => 91-92
[company] => Veer Signages Pvt. Ltd.
[city] => Gurgaon
[country] => India
)
Array
(
[name] => Prakash Tiwari
[email] => digital
[designation] => Director
[website] =>
[phone] => 91-981
[company] => Digital Semiconductors Pvt. Ltd
[city] => New Delhi
[country] => India
)
使用foreach循环获取此数组
foreach($metadata as $key=>$value)
{
echo $value['name'];
}
输出第一个数组
output yB9VGI
PdD9DNI
我只想取['指定']&密钥值对中的[' company']。 喜欢
[designation] => manager
[company]=>google
请告诉我哪里有错误,欢迎提出任何建议。
答案 0 :(得分:1)
这就是你要找的东西:
foreach($metadata as $key => $value) {
if ($key === 'designation' || $key === 'company')
echo $value;
}
答案 1 :(得分:0)
试试这个
foreach($metadata as $value)
{
echo $value->name;
}
答案 2 :(得分:0)
试
foreach($arr as $k=>$v) {
if($k == 'designation' || $k == 'company')
$newarr[][$k] = $v;
}
print_r($newarr);
答案 3 :(得分:0)
最后我做到了这一点 它工作正常如下
foreach($metadata as $key => $value)
{
if ($key == 'designation' )
$designation= $value;
elseif($key == 'company')
$company= $value;
}
echo“D = $ names and C = $ company \ n”;