Hi,
I’d like to substitute array keys but I’m new to PHP and I don’t know how to do it – I was hoping you could help.
The source array looks like this:
"user_cards": {
"1": {
"num_owned": "9",
"num_used": "0"
},
"2": {
"num_owned": "0",
"num_used": "0"
},
"3": {
"num_owned": "0",
"num_used": "0"
},
"4": {
"num_owned": "8",
"num_used": "0"
},
"5": {
"num_owned": "11",
"num_used": "0"
}
I’d like to substitute the keys “1,2,3,4,5” etc. with the array values from a txt file called db.txt
That array looks like this:
<?php
$d[1] = array("Infantry",0);
$d[2] = array("Infantry",2);
$d[3] = array("Infantry",3);
$d[4] = array("Bazooka Marine",0);
$d[350] = array("Bazooka Marine",2);
$d[351] = array("Bazooka Marine",3);
$d[5] = array("Medic",0);
?>
so my current output of
1
2
3
4
5
would be replaced with
Infantry
Infantry
Infantry
Bazooka Marine
Medic
this is what I have so far:
<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', true);
include_once('db.txt');
$json = file_get_contents("TU.json");
$json = json_decode($json, true);
foreach ($json['user_cards'] as $row => $v)
{
echo "$row<br>";
// foreach ($v as $key => $val)
// {
// echo "$key : $val'<br>";
// }
}
?>
I don’t know if this’ll make a difference to any advice you may offer but I will be trying to append the value from "num_owned" to each name too.