Hello i am new here also new in php

i have problem with my code

$seller_id = $listings[]['Account_ID'];
$seller_info = $rlAccount -> getProfileInfo( $seller_id );
$rlSmarty -> assign_by_ref( 'seller_info', $seller_info );
i get this error Fatal error: Cannot use [] for reading in

the array is

Array (
    [0] => Array
        (
            [name] => Automobiles
            [ID] => 1
            [Account_ID] => 0
        )
    [1] => Array
        (
            [name] => Automobiles
            [ID] => 2
            [Account_ID] => 1
        )
    )
.
.
.

Please help how i can fix it

Member Avatar for diafol

You can't get data like this as [] doesn't refer to anything. You can certainly set data like this.

$seller_id = $listings[0]['Account_ID']; //will work

Thank you ardav, i know its work like this but its will get just one array details

Member Avatar for diafol

You don't say what you want. My crystal ball is all fuzzy. Care to elaborate?

I am sorry, what i want get all arrays for listings (0, 1, 2, ....., etc)

Member Avatar for diafol
foreach($listings as $listing){
  $seller_id[] = $listing['AccountID'];
}

will place all the account ids into an array called $seller_id.

That it?

sorry, i don't get the error but still not work

Member Avatar for diafol

have you tried

print_r($seller_id);

after the code I gave you?

I seem to jump on threads that ardav has posted on a lot, but I wanted to chime in here just to advocate the usage of print_r() and var_dump() when struggling with an array-related issue.

I consider these two functions to be extremely useful, and personally can say that once I started using them, my understanding of (multidimensional) arrays was greatly improved.

Yes
Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => ) Output has already been sent to the browser at

Member Avatar for diafol

this suggests that $listing[...] are empty.

Do

print_r($listings);
foreach($listings as $listing){
  $seller_id[] = $listing['AccountID'];
}
print_r($seller_id);

See if this shines any light on it.

i attached function for this code i hope it help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.