I have small problem with my project. I don't know much, because I'm only learning now PHP arrays, I want to create some like this
PewDiePie
PewDiePie1
PewDiePie2
and on click href
to account_id.
Here is PHP code:
$link = $_GET['search'];
$str_data = file_get_contents("https://api.worldoftanks.eu/wot/account/list/?application_id=ID_OF_APPLICATION&search=$link");
$data = json_decode($str_data,true);
function echo_array($a, $key){
foreach($a as $key1 => $array1){
if(!is_array($array1)){
echo "$key $key1 : $array1 </br>";
}else{
echo_array($array1,"$key $key1");
}
}
}
echo_array($data,'');
This is output of PHP file
status: ok
meta count: 100
data 0 nickname: Pewdiepie
data 0 account_id: 501337127
data 1 nickname: Pewdiepie00
data 1 account_id: 510468398
data 2 nickname: pewdiepie007
data 2 account_id:511343434
but I want to make only some like $nickname and $account_id , but when I tried, it was been a fail. Will you advise me?
Your function need to be:
function echo_array($a, $key){
foreach($a['data'] as $data){
echo $data['nickname'];
echo $data['account_id'];
}
}
If you post the Json result, i can more explain how acces to the children node
Okey i have solution, because in code is 2 same arrays
$link = $_GET['search'];
$str_data = file_get_contents("https://api.worldoftanks.eu/wot/account/list/?application_id=#&search=$link");
//there is data $data = json_decode($str_data,true);
function echo_array($a, $key){
foreach($a['data'] as $data1){
//and there is data echo $data['nickname'];
echo $data['account_id'];
}
}
echo_array($data,'');
i changed to
$link = $_GET['search'];
$str_data = file_get_contents("https://api.worldoftanks.eu/wot/account/list/?application_id=#&search=$link");
$data = json_decode($str_data,true);
function echo_array($a, $key){
foreach($a['data'] as $data1){
echo $data1['nickname'];
echo $data1['account_id'];
}
}
echo_array($data,'');
and now is working, Thank you Jonathan, have a nice day:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.