Jump to content

Array Syntax Question....


drbigfresh

Recommended Posts

I am currently building an array as I loop through some data. Currently I am doing this (I've shortened the array for posting purposes):

 

if(is_array($ListInformation)) {

 

array_push ($ListInformation,array(

listid => $result->fields['id']

)); //End Master Array

 

} else {

 

$ListInformation = array(

array(

listid => $result->fields['id']

),); //End Master Array

 

} // End We Have Info.

 

 

Is there a better way to do this so I don't have to add the array info in 2 separate steps? Since right now I am checking to see if it is an array, and if so I am using array_push. If it isn't an array I create it. But it is a little cumbersome....

Link to comment
Share on other sites

Hmmmm... I can't seem to get it to work. This is my code that I have:

 

(it is inside a loop going though information from a database)

 

if(is_array($ListInformation)) {

 

array_push ($ListInformation,array(

listid => $result->fields['id'],

listname => $result->fields['listname'],

listdescription => $result->fields['description'],

thumbsup => $VoteUp,

thumbsdown => $VoteDown,

listcreated =>$result->fields['created'],

totalitems => $result->fields['totalitems'],

totalviews => $result->fields['totalviews'],

sadellink => $sadellink,

city => $result->fields['city'],

state => $result->fields['state'],

country => $result->fields['country'],

published => $result->fields['published'],

publisheddate => $result->fields['publisheddate'],

zip => $result->fields['zipcode'],

publicedit => $result->fields['publicedit'],

url => $result->fields['url'],

permalink =>  $PermaURL,

keywords =>  $result->fields['keywords'],

listrssfeed =>  $RSSFeed,

recordsreturned =>  $RecordsReturned,

creatorid =>  $result->fields['uid']

)); //End Master Array

 

 

} else {

 

 

$ListInformation = array(

array(

listid => $result->fields['id'],

listname => $result->fields['listname'],

listdescription => $result->fields['description'],

listcreated =>$result->fields['created'],

thumbsup => $VoteUp,

thumbsdown => $VoteDown,

totalitems => $result->fields['totalitems'],

totalviews => $result->fields['totalviews'],

sadellink => $sadellink,

city => $result->fields['city'],

state => $result->fields['state'],

country => $result->fields['country'],

published => $result->fields['published'],

publisheddate => $result->fields['publisheddate'],

zip => $result->fields['zipcode'],

publicedit => $result->fields['publicedit'],

url => $result->fields['url'],

permalink => $PermaURL,

keywords =>  $result->fields['keywords'],

listrssfeed =>  $RSSFeed,

recordsreturned =>  $RecordsReturned,

creatorid =>  $result->fields['uid']

),); //End Master Array

 

 

} // End Is Array

 

Link to comment
Share on other sites

$ListInformation = array();

while ... {
$ListInformation[] = array(
		'listid' => $result->fields['id'],
		'listname' => $result->fields['listname'],
		'listdescription' => $result->fields['description'],
		'thumbsup' => $VoteUp,
		'thumbsdown' => $VoteDown,
		'listcreated' =>$result->fields['created'],
		'totalitems' => $result->fields['totalitems'],
		'totalviews' => $result->fields['totalviews'],
		'sadellink' => $sadellink,
		'city' => $result->fields['city'],
		'state' => $result->fields['state'],
		'country' => $result->fields['country'],
		'published' => $result->fields['published'],
		'publisheddate' => $result->fields['publisheddate'],
		'zip' => $result->fields['zipcode'],
		'publicedit' => $result->fields['publicedit'],
		'url' => $result->fields['url'],
		'permalink' =>  $PermaURL,
		'keywords' =>  $result->fields['keywords'],
		'listrssfeed' =>  $RSSFeed,
		'recordsreturned' =>  $RecordsReturned,
		'creatorid' =>  $result->fields['uid']
	);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.