我需要从$ mydata变量中提取地址。
我有这个代码向我显示我的数据:
foreach($landerssss['domains'] as $mydata)
{
echo '<pre>' . print_r($mydata, TRUE) . '</pre>';}
在上面的代码中没有错误,下面的行显示了$ mydata变量中的内容。
这是$ mydata变量中的内容:
Array
(
[0] => Array
(
[address] => aloran
[mainDomain] =>
)
[1] => Array
(
[address] => ozamiz
[mainDomain] =>
)
[2] => Array
(
[address] => manila
[mainDomain] =>
)
[3] => Array
(
[address] => cebu
[mainDomain] =>
)
)
Array
(
[0] => Array
(
[address] => bacolod
[mainDomain] =>
)
[1] => Array
(
[address] => bukidnon
[mainDomain] => 1
)
[2] => Array
(
[address] => davao
[mainDomain] =>
)
[3] => Array
(
[address] => boracay
[mainDomain] =>
)
[4] => Array
(
[address] => palawan
[mainDomain] =>
)
[5] => Array
(
[address] => bohol
[mainDomain] =>
)
[6] => Array
(
[address] => calabarson
[mainDomain] =>
)
[7] => Array
(
[address] => NCR
[mainDomain] =>
)
[8] => Array
(
[address] => baguio
[mainDomain] =>
)
[9] => Array
(
[address] => manila
[mainDomain] =>
)
[10] => Array
(
[address] => cagayan
[mainDomain] =>
)
[11] => Array
(
[address] => iligan
[mainDomain] =>
)
[12] => Array
(
[address] => sindangan
[mainDomain] =>
)
[13] => Array
(
[address] => dipolog
[mainDomain] =>
)
[14] => Array
(
[address] => calamba
[mainDomain] =>
)
)
我需要提取所有地址,所以我尝试使用
foreach ($mydata[0]['sddress'] as $key) {
}
但我收到了错误:
Warning: Illegal string offset 'address' in /srv/users/serverpilot/apps/ruleswitcherandchecker/public/CTAchecker/index.php on line 131
Warning: Invalid argument supplied for foreach() in /srv/users/serverpilot/apps/ruleswitcherandchecker/public/CTAchecker/index.php on line 131
请帮助:(
答案 0 :(得分:0)
看看那个转储,看起来你需要另外一组foreach
,因为它的嵌套:
foreach($landerssss['domains'] as $mydata) {
foreach ($mydata as $key) {
echo $key['address']; // and so forth
}
}