This question already has answers here:
Parse query string into an array
(12 answers)
Closed 8 years ago.
My chain in PHP is like the following:
$chain = "m=toto&i=12&a=new";
How to get m, i and a values ?
Thanks.
Try This:
<?php
$chain = "m=toto&i=12&a=new";
parse_str($chain,$array);
This will create an array named $array containing all values you can access them as $array['m']
You can Print all this by:
print_r($array);
Related
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 2 years ago.
I Have a string like this
{"Account":{"Currency":"SGD","CreditLimit":0.0000,"Balance":1649.5700},"Status":36,"Code":891,"Message":"Success"}-
I need the value of Balance.
I tried like this.
$string = '{"Account":{"Currency":"SGD","CreditLimit":0.0000,"Balance":1649.5700},"Status":1,"Code":1,"Message":"Success"}-';
$withCharacter = strstr($string, 'Balance":');
echo substr($withCharacter, 1);
Tried to use explode also but no luck.
This seems like a valid JSON, why not json_decode and find the value:
$i = json_decode('{"Account":{"Currency":"SGD","CreditLimit":0.0000,"Balance":1649.5700},"Status":36,"Code":891,"Message":"Success"}');
echo $i->Account->Balance;
This question already has answers here:
How to add elements to an empty array in PHP?
(8 answers)
Closed 5 years ago.
Given this PHP array:
$options['systems'] = array(1, 2, 3)
How would I append the value 4 to the $systems array within the $options array?
You could use array_push to push additional items like so:
array_push($options['systems'], 4);
Or the shorthand version:
$options['systems'][] = 4;
You can use php array_push function. Like this. array_push($options['systems'],4);
you can read the detail of array_push from below link.array_push manual
This question already has answers here:
Parse query string into an array
(12 answers)
Closed 7 years ago.
This is the value i get from db.
pkid=1&ordernumber=54322&ordervalue=12345&response=2&scheduleId=1
Want to extract response from this.That is 2.
Here it is
$str ='pkid=1&ordernumber=54322&ordervalue=12345&response=2&scheduleId=1';
parse_str($str);
echo $response; // output :- 2
This question already has answers here:
json decode in php
(5 answers)
Closed 8 years ago.
How to spit this set of data using php? this data generated from some php to my mysql database.
[{"id":"1","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Company","value":"Destination Queenstown"},{"id":"2","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Your Name","value":"Ella Zhang"}]
now i just need to get id=2 and its value in the output.
It is a JSON data.Try with -
$array = '[{"id":"1","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Company","value":"Destination Queenstown"},{"id":"2","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Your Name","value":"Ella Zhang"}]';
$array = json_decode($array);
echo $array[1]->id;
This question already has answers here:
How to "flatten" a multi-dimensional array to simple one in PHP? [duplicate]
(23 answers)
Closed 9 years ago.
how to split received values of an array into a new array?
so from this:
[["+","+","+"],["-","+","+"],["*","+","+"],["\/","+","+"],
to this:
["+"],["+"],["+"],["-"],["+"],["+"],["*"],["+"],["+"],
can someone help me?
Flatten your array by looping through it
$aFlattened = array();
foreach($aOriginalArray AS $aOperators){
$aFlattened = array_merge($aFlattened, $aOperators);
}