Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a post value named $_POST['John'] and I want to insert the post name "John" into a variable but not its value. How can I achieve this? Code Sample:
$_POST['John'] = "value";
array_keys is PHP function which is returning the keys from an array, you have only single array than we can use 0 as the key. if you have more than one array element you can use loop.
You can use array_keys as you mentioned there is one parameter use
$a = array_keys($_POST)[0];
https://3v4l.org/NUkkL
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Below are the results of my query. I would just like to return the refundable_amount value. Which for this query $4.04
a:1:{i:0;a:19:{s:8:"label_id";i:3324543;s:8:"tracking";s:22:"9400136205309684548265";s:17:**"refundable_amount";d:4.04**;s:7:"created";i:1614781854687;s:10:"carrier_id";s:4:"usps";s:12:"service_name";s:23:"USPS - First Class Mail";s:6:"status";s:9:"PURCHASED";s:22:"commercial_invoice_url";N;s:12:"package_name";s:11:"Single Kcup";s:9:"is_letter";b:0;s:13:"product_names";a:1:{i:0;s:28:"Multiple Aware";}s:11:"product_ids";a:1:{i:0;i:1212;}s:15:"receipt_item_id";i:72845982;s:12:"created_date";i:1614781859000;s:11:"expiry_date";i:1630333858000;s:15:"main_receipt_id";i:54663164;s:4:"rate";d:4.04;s:8:"currency";s:3:"USD";s:12:"label_cached";i:1614781863000;}}
Thank you in advance for any help.
You have typo, in near the "Multiple Aware" output, it should be 14, if you correct it like below,
Then you can use php unserialize function
$text = unserialize ('a:1:{i:0;a:19:{s:8:"label_id";i:3324543;s:8:"tracking";s:22:"9400136205309684548265";s:17:"refundable_amount";d:4.04;s:7:"created";i:1614781854687;s:10:"carrier_id";s:4:"usps";s:12:"service_name";s:23:"USPS - First Class Mail";s:6:"status";s:9:"PURCHASED";s:22:"commercial_invoice_url";N;s:12:"package_name";s:11:"Single Kcup";s:9:"is_letter";b:0;s:13:"product_names";a:1:{i:0;s:14:"Multiple Aware";}s:11:"product_ids";a:1:{i:0;i:1212;}s:15:"receipt_item_id";i:72845982;s:12:"created_date";i:1614781859000;s:11:"expiry_date";i:1630333858000;s:15:"main_receipt_id";i:54663164;s:4:"rate";d:4.04;s:8:"currency";s:3:"USD";s:12:"label_cached";i:1614781863000;}}');
you can get the value as below,
echo $text[0]['rate'];
will output
4.04
For more information about this function you can visit
https://www.php.net/manual/en/function.unserialize.php
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
When we pass an array as an argument to a function, what actually gets passed?
Someone told me that it is "Base address of the array"? but I am not sure about it. How this array is processed then?
this is the answer: Are arrays in PHP passed by value or by reference?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have some problem in the following array, I want to access the value of the "videoid" from the given array that is been fetched with json_encode
Array ( [0] => {"DATA":[{"videoid":"462"}]"});
Please help me so that I can fetch the value of "videoid".
If you have a php string containing JSON and you want to access the videoid property use php's json_decode function :
$json='{"DATA":[{"videoid":"462"}]}';
$array=json_decode($json);
var_export(current($array->DATA)->videoid);//returns '462'
See the code in action here :
http://sandbox.onlinephpfunctions.com/code/485b94b6423972b8c87eec885da8fdc5a56c6acd
Here you are. Should work.
If you only want one value I would suggest you make sure to get the json in a different format if possible:
$array[0]->data[0]->videoid;
If you have more videoids in your DATA than you need to loop it to get it
foreach($array[0]->data as $key => $value){
$dosomethingwithit = $value;
}
Hope it helps
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I know this must be a huge newbie question, but I didn't find the correct answer. Let's see. I have an array set:
$global_array = array();
Then, I want to add an arry inside $global_array, but I dont want the keys. So, the result I want to get is:
$global_array = array(
array(
'bla',
'bla'
)
);
Sorry for the noob question. Thanks!
This should help:
$global_array[] = array('bla','bla');
All arrays will have keys...
If not defined as default 0,1,2,3...
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a php array which is created from data in an sql database.
All I want to do is recreate that identical array on another site.
I can print_r it no worries. But how would I output the structure of the array so that I can go as follows on the new site.
$newvar = array(.....);
I'm sure it's a very simply question, But I can't find an answer.
serialize Try this function. I think this is what you need
you can use json_encode to send your array and keep the structure of your array.