Fatal error: Cannot use [] for reading in

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


  $seller_id = $listings[]['Account_ID'];

You have to put a valid key in the otherwise PHP cannot know which array element you are after.

In your case the keys are numerical, starting at 0 - so this gets you the first one.


  $seller_id = $listings[0]['Account_ID'];

Generally to go through all the elements in such a numerically keyed array you’d assign a counter or loop through them:


foreach( $listings as $k => $value){
echo $value['Account_ID'];
}

If you expect to get only one sub-array, you’d need to know its key – unless it was first or last.

Thanx for your replay

its work but its give me last account ID in listing i add it like this right?


	foreach( $listings as $k => $value){

 
	
		    $seller_id =  $value['Account_ID'];
			$seller_info = $rlAccount -> getProfileInfo( $seller_id );
			$rlSmarty -> assign_by_ref( 'seller_info', $seller_info );

	
} 

and if type


foreach( $listings as $k => $value){
echo $value['Account_ID'];
}  

i get in my website like this
0222233355Output has already been sent to the browser at

and its give me last account ID

It looks to me as if you are having problems with Smarty.

You need to stop and identify which values you are setting Smarty up to use.

Make sure you are assigning the values you expect first – use a debug script to output all the data onto the page, then re-introduce your Smarty template.

It is impossible to say unless you show us all the code you are using.

Hello Cups
i attached 2 files for this code see it please my it help you

Can anyone help me??? :frowning: