调用 url 中的数组键
Calling on an array key in the url
大家好,我在做一个项目时遇到了一些麻烦。我需要能够获取数组的键并调用 www.blach.com/1 中的键 1 并且我需要显示该键内的所有值。我将如何去做,我已经搜索了一段时间,但到目前为止,我尝试过的一切都没有奏效,我们将不胜感激。
Array(
[0] => Array
(
[boxId] => 917
[contentId] => 72
[sectionType] => hp_spl_contestants
[contentTypeId] => 83
[categoryId] => 0
[countryId] => 5
[data] => {"title":"Contestant No.1","button_txt":"Latest From","image":"2d4f8f52d49d1ab9930bc40157013a31.jpg","author":"Meenakshi Negi","url":"","date":"2012-10-04 18:16:30","badget":0,"badget_date":""}
[insertDate] => 2012-10-05 21:05:57
[sortorder] => 1
[sitename] => bb6
)
[1] => Array
(
[boxId] => 918
[contentId] => 63
[sectionType] => hp_spl_contestants
[contentTypeId] => 83
[categoryId] => 0
[countryId] => 5
[data] => {"title":"Contestant No.2","button_txt":"Latest From","image":"37154a5322838f61fb60cc24c8b5fe04.jpg","author":"Meenakshi Negi","url":"","date":"2012-10-04 18:09:06","badget":0,"badget_date":""}
[insertDate] => 2012-10-05 21:06:16
[sortorder] => 2
[sitename] => bb6
)
我试过了
$obj = json_decode($ApiData);
$Array = json_decode(json_encode($obj), true);
$data = $Array;
$id = $_GET['id'];
foreach ($data[$id] as $key=>$value){
echo "$key -> $value<br>";
}
?>
但是returns出现以下错误
Invalid argument supplied for foreach()
当删除 foreach 中的 [$id] 并传入数组时 returns this
0 -> Array
1 -> Array
2 -> Array
3 -> Array
4 -> Array
5 -> Array
.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ handler.php?id=
handler.php
<?php
$data = Array();
//here you load $data with whatever you want.
$id = $_GET['id'];
foreach ($data[$id] as $key=>$value){
echo "$key -> $value<br>";
}
?>
你需要使用 get 方法来调用 url,你的 url 中的 1 有一些像数字这样的值,那么你可以这样做,$url = $_GET['number'];
然后您可以使用 $url
作为数组键。
大家好,我在做一个项目时遇到了一些麻烦。我需要能够获取数组的键并调用 www.blach.com/1 中的键 1 并且我需要显示该键内的所有值。我将如何去做,我已经搜索了一段时间,但到目前为止,我尝试过的一切都没有奏效,我们将不胜感激。
Array(
[0] => Array
(
[boxId] => 917
[contentId] => 72
[sectionType] => hp_spl_contestants
[contentTypeId] => 83
[categoryId] => 0
[countryId] => 5
[data] => {"title":"Contestant No.1","button_txt":"Latest From","image":"2d4f8f52d49d1ab9930bc40157013a31.jpg","author":"Meenakshi Negi","url":"","date":"2012-10-04 18:16:30","badget":0,"badget_date":""}
[insertDate] => 2012-10-05 21:05:57
[sortorder] => 1
[sitename] => bb6
)
[1] => Array
(
[boxId] => 918
[contentId] => 63
[sectionType] => hp_spl_contestants
[contentTypeId] => 83
[categoryId] => 0
[countryId] => 5
[data] => {"title":"Contestant No.2","button_txt":"Latest From","image":"37154a5322838f61fb60cc24c8b5fe04.jpg","author":"Meenakshi Negi","url":"","date":"2012-10-04 18:09:06","badget":0,"badget_date":""}
[insertDate] => 2012-10-05 21:06:16
[sortorder] => 2
[sitename] => bb6
)
我试过了
$obj = json_decode($ApiData);
$Array = json_decode(json_encode($obj), true);
$data = $Array;
$id = $_GET['id'];
foreach ($data[$id] as $key=>$value){
echo "$key -> $value<br>";
}
?>
但是returns出现以下错误
Invalid argument supplied for foreach()
当删除 foreach 中的 [$id] 并传入数组时 returns this
0 -> Array
1 -> Array
2 -> Array
3 -> Array
4 -> Array
5 -> Array
.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ handler.php?id=
handler.php
<?php
$data = Array();
//here you load $data with whatever you want.
$id = $_GET['id'];
foreach ($data[$id] as $key=>$value){
echo "$key -> $value<br>";
}
?>
你需要使用 get 方法来调用 url,你的 url 中的 1 有一些像数字这样的值,那么你可以这样做,$url = $_GET['number'];
然后您可以使用 $url
作为数组键。