I regularly have to pick certain values out of a large array. While I understand my way of doing this is probably not the absolute right way, but in this system it is the way I should do it.
Example (simplified) array:
$data = array (
'api' =>
array (
'update_id' => 94594942,
'message' =>
array (
'message_id' => 141,
'from' =>
array (
'id' => 1251597,
'first_name' => 'Testuser',
),
'chat' =>
array (
'id' => '124630',
'title' => 'TESTGROUP',
'type' => 'group',
),
'date' => '1460712410',
'text' => 'tryout',
'valid' => true,
),
'list' =>
array (
0 => 'one',
1 => 'two',
2 => 'three',
),
),
);
My desired export/dump as a plain string:
$result = "
data['api']['update_id'] = 94594942;
data['api']['message']['message_id'] = 141;
data['api']['message']['from']['id'] = 1251597;
data['api']['message']['from']['first_name'] = 'Testuser';
data['api']['message']['chat']['id'] = '124630';
data['api']['message']['chat']['title'] = 'TESTGROUP';
data['api']['message']['chat']['type'] = 'group';
data['api']['message']['date'] = '1460712410';
data['api']['message']['text'] = 'tryout';
data['api']['message']['valid'] = true;
data['api']['list'][] = 'one';
data['api']['list'][] = 'two';
data['api']['list'][] = 'three';
";
I'm calling it a 'horizontal' array representation - I don't quite know what's the official name for it.
I've tried to convert the array with json_encode() and var_export(), and manually parse it, but it doesn't seem to be the right way to do it and gives me headaches. Any tips?
var_export($data, true);with a different template.json_encode/json_decode?