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
Related
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.
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
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];
I've managed to confuse myself here, I have an object that I've converted to an array and now want to get the value of:
echo var_dump((array)$obj['country_id']);
Gives an output of:
array(1) { [0]=> string(2) "GB" }
How do I simply get "GB"?
try this:
$result = (array)$arr['country_id'];
echo $result[0];
I get a returned result from an API in stdClass format. I don't know anything about this type of data. So here it looks like:
object(stdClass)#41 (1) {
["return"]=>
object(stdClass)#42 (7) {
["afterPayOrderReference"]=> string(32) "d4ab78df6ab2ef84194dd1c1d66240b8"
["checksum"]=> string(32) "4f8826a99e9c0a67e578d04b6a625117"
["resultId"]=> int(0)
["statusCode"]=> string(1) "A"
["timestampIn"]=> float(1408533108515)
["timestampOut"]=> float(1408533113616)
["transactionId"]=> int(129525)
}
}
What I need is retrieving the statusCode value. I tried doing like in a post I read:
$array = (array) $stringResult;
$array[0]->statusCode;
But it didn't work. Please, someone explain to me in the simplest way because it's really new to me. Thanks.
Object properties are accessed with the -> operator. Just do:
echo $stringResult->return->statusCode;
If you wanted an array you would access like this since the array contains an object:
$array = (array)$stringResult;
echo $array['return']->statusCode;
Its an object array, so just as you call the array element,
echo $stringResult["return"]->statusCode