A var_dump of $_POST gives the following result:
array(1) {
["postID"]=>
array(1) {
[0]=>
string(2) "76"
}
}
I want to bind the data from position [0] -> "76" to a variable called $id.
What is the correct way to handle this?
Thanks in advance!
You can access this value doing:
$id = $_POST['postID'][0];
Related
I have a dump of data :
var_dump($steps);
and results are :
object(Drupal\form\Manager\StepManager)#490 (1) {
["steps":protected]=>
array(1) {
[1]=>
object(Drupal\form\Step\StepOne)#494 (2) {
["step":protected]=>
int(4)
["values":protected]=>
array(1) {
["key"]=>
string(3) "123"
}
}
but I tried using :
$steps[1]->values->key but its having an error, its not available directly?
where did I miss?
The index to the first item – and only item in your case – is 0, and not 1. So this should work:
$steps[0]->...
The number 1 in the var_dump shows the size of the array:
["steps":protected]=>
array(1) { // This array contains one item
Your $steps array with in a object of Drupal\form\Manager\StepManager
and you accessed key from values object but your output shows you have a values array not object.
array(1) {
["key"]=>
string(3) "123"
}
So try this in var_dump() I think its worked
var_dump($steps->steps[1]->values["key"]);
I'm working on a php magento script which have a array variable for store some script urls.
array variable $items['js']
var_dump
array(1) {
[""]=>
array(17) {
["prototype/prototype.js"]=>
string(22) "prototype/prototype.js"
["varien/form.js"]=>
string(14) "varien/form.js"
["mage/translate.js"]=>
string(17) "mage/translate.js"
["mage/cookies.js"]=>
string(15) "mage/cookies.js"
["wyomind/layer/native.history.js"]=>
string(31) "wyomind/layer/native.history.js"
["varien/weee.js"]=>
string(14) "varien/weee.js"
["geissweb/vatvalidation-min.js"]=>
string(29) "geissweb/vatvalidation-min.js"
}
}
I tried to access the "geissweb/vatvalidation-min.js" value like this
$items['js']['geissweb/vatvalidation-min.js']
but it return empty value, is there have a way to get that value without use foreach or for loop. Thank You
Your index is '', shown by...
array(1) {
[""]=>
so you need to use...
$items['js']['']['geissweb/vatvalidation-min.js']
You have your variable $items['js'] as an array of arrays what your looking for without a foreach is this :
$items['js'][0]['geissweb/vatvalidation-min.js'] is not valid
after tests
$items['js'][""]['geissweb/vatvalidation-min.js'] is valid.
I am trying to get the value of currentPdfDownload and max_download_limit from my $result array variable
var_dump($result); output:-
array(1) {
[0]=>
object(stdClass)#1529 (2) {
["currentPdfDownload"]=>
string(2) "42"
["max_download_limit"]=>
string(2) "20"
}
}
I try this:
echo $result['currentPdfDownload']." ".$result['max_download_limit'];
But it does not give any result.
Please highlight what I am doing wrong?
Thanks in advance
You need to do it like below:-
echo $result[0]->currentPdfDownload." ".$result[0]->max_download_limit;
Note:- Your array have an index 0 and on that index it have an object array so you need to use [0] and -> to fetch it's indexes as property of an object
pls, i would like to get the values of the $aa variable, i'm using the mysqli_fetch_all because all the values need to be used in another layer.
Thanks
$aa = mysqli_fetch_all($ttt,MYSQLI_ASSOC);
Output with var_dump($aa):
array(2) { [0]=> array(1) { ["followe"]=> string(8) "bammyww " } [1]=> array(1) { ["followe"]=> string(5) "demo " } }
i have tried using $aa['followe'] , but i'm getting invalid index error.
Just loop through it. It's an array containing associative arrays.
foreach($aa as $item)
{
$item['followe'] // do something with this.
}
Instead of $aa['followe'], try:
$aa[0]['followe'];
as its a multi-dimension array. And the right approach to get all the array element is using foreach() like:
foreach($aa as $item)
{
$item['followe']
}
use
$aa[0]['followe'];
$aa[0] is array(1) { ["followe"]=> string(8) "bammyww " }
$aa[0]['followe'] is string(8) "bammyww "
You can also use array_column as
array_column($aa,'followe');//retrieves values associated with the key followe
I have been trying to figure this out for a while now. Please any advice would be appreciated. I just need to access the array for ["Item"]. How do I gain access to this?
array(1) {
[0]=>
object(SimpleXMLElement)#16 (2) {
["#attributes"]=>
array(2) {
["Name"]=>
string(10) "AuthorList"
["Type"]=>
string(4) "List"
}
["Item"]=>
array(3) {
[0]=>
string(9) "Smith, Joe"
[1]=>
string(10) "Peter, Ann"
[2]=>
string(18) "Magoo, Mr"
}
}
}
Assuming this structure is in a variable called var1, you should be able to access Item using:
$var1[0]->Item // returns the array
I try to explain it.
Like you see, your first array index is an object.
If you see something like this in your var_dump than you can access it through deferencing the object.
It's the same like you would create an object and would like to access a public variable:
$var1 = new Object();
// when your Object variables are public so you could access them by deference the Object
echo $var1->myVariable; // will echo the public variable "myVariable"
So the answer from adam is the right one :)