php array help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kshitizgp
Forum Newbie
Posts: 10
Joined: Sat Dec 03, 2011 12:56 am

php array help

Post by kshitizgp »

Array
(
[1] => Array
(
[id] => 2
[menu_name] => php
[type] => 2
[visible] => 1
)

guyz i have this array as output ...i want to change the code so that when i type id =2 the array should be

[2] =id
{
[menu_name] => php
[type] => 2
[visible] => 1
)

it should fetch from id =2 and give me the output ..please hlp sort of urgent


the code is <?php

$rs = mysql_query("select * from subject",$connection);

while( $ds = mysql_fetch_assoc($rs) )
{
$arrList[] = $ds;
}

echo '<pre>';
echo $arrList[2]['id'];///exit;
print_r($arrList);exit


/// help
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php array help

Post by Celauran »

Code: Select all

while ($ds = mysql_fetch_assoc($rs))
{
  $arrList[$ds['id']] = array('menu_name' => $ds['menu_name'], 'type' => $ds['type'], 'visible' => $ds['visible']);
}
Post Reply