RE: [PHP] remove keys from array
http://www.php.net/manual/en/function.unset.php So if you had: $foo = Array ( [0] = 2, [ID] = 2, [1] = asdasd, [CategoryName] = asdasd ) ); unset($foo[0]); unset($foo[1]); Yields: $foo = Array ( [ID] = 2, [CategoryName] = asdasd ) ); DÆVID -Original Message- From: Richard Lynch [mailto:[EMAIL PROTECTED] Sent: Monday, June 12, 2006 12:49 PM To: Ahmed Abdel-Aliem Cc: php-general@lists.php.net Subject: Re: [PHP] remove keys from array On Sun, June 11, 2006 6:57 am, Ahmed Abdel-Aliem wrote: hi all when i have array in the form of : Array ( [0] = 2 [ID] = 2 [1] = asdasd [CategoryName] = asdasd ) ) how can i make it in the form of : Array ( [ID] = 2 [CategoryName] = asdasd ) ) can anyone help me with that plz ? I don't even understand the question... Where did this array come from? -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] remove keys from array
On Sun, June 11, 2006 6:57 am, Ahmed Abdel-Aliem wrote: hi all when i have array in the form of : Array ( [0] = 2 [ID] = 2 [1] = asdasd [CategoryName] = asdasd ) ) how can i make it in the form of : Array ( [ID] = 2 [CategoryName] = asdasd ) ) can anyone help me with that plz ? I don't even understand the question... Where did this array come from? -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] remove keys from array
Crap.. I remember seeing an example of something that yielded arrays like this and now I can't find it. It basically created an array (from a database I thought.. but can't find the example under mysql_fetch_assoc or mysql_fetch_array... thought it was in the standard PHP documentation (not the user comments). Anyway, it looked just like this. first array element key = ID and value = 2 second array element key = CategoryName and value = asdasd But you ended up with an array that merged an associative array and a regular indexed array. So you get, in addition to the above, a 0 = 2 and 1 = asdasd. Looks like he wants just the associative side of it.. not the indexed. -TG = = = Original message = = = On Sun, June 11, 2006 6:57 am, Ahmed Abdel-Aliem wrote: hi all when i have array in the form of : Array ( [0] = 2 [ID] = 2 [1] = asdasd [CategoryName] = asdasd ) ) how can i make it in the form of : Array ( [ID] = 2 [CategoryName] = asdasd ) ) can anyone help me with that plz ? I don't even understand the question... Where did this array come from? ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] remove keys from array
This looks to me as printet result array from database: $query = mysql_query(select * from table); $result = mysql_fetch_array($query); if you print_r($result); you'll get doubled values. use $result = mysql_fetch_array($query, MYSQL_ASSOC); for singles check: http://us2.php.net/manual/en/function.mysql-fetch-array.php -afan Crap.. I remember seeing an example of something that yielded arrays like this and now I can't find it. It basically created an array (from a database I thought.. but can't find the example under mysql_fetch_assoc or mysql_fetch_array... thought it was in the standard PHP documentation (not the user comments). Anyway, it looked just like this. first array element key = ID and value = 2 second array element key = CategoryName and value = asdasd But you ended up with an array that merged an associative array and a regular indexed array. So you get, in addition to the above, a 0 = 2 and 1 = asdasd. Looks like he wants just the associative side of it.. not the indexed. -TG = = = Original message = = = On Sun, June 11, 2006 6:57 am, Ahmed Abdel-Aliem wrote: hi all when i have array in the form of : Array ( [0] = 2 [ID] = 2 [1] = asdasd [CategoryName] = asdasd ) ) how can i make it in the form of : Array ( [ID] = 2 [CategoryName] = asdasd ) ) can anyone help me with that plz ? I don't even understand the question... Where did this array come from? ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] remove keys from array
On 6/11/06, Ahmed Abdel-Aliem [EMAIL PROTECTED] wrote: when i have array in the form of : Array ( [0] = 2 [ID] = 2 [1] = asdasd [CategoryName] = asdasd ) ) how can i make it in the form of : Array ( [ID] = 2 [CategoryName] = asdasd ) ) To remove a single element you can use unset: unset($arr[0]);. To remove all the elements with integer indices you could just loop, check, and unset those ones. What do you need to do this for? Your examples looks like arrays got from mysql_fetch_array. If this is so, using mysql_fetch_assoc() instead of that will get you only the associative array. Rabin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] remove keys from array
if you pull this array from mysql use this: $query = mysql_query(SELECT * FROM table); $result = mysql_fetch_array($query, MYSQL_ASSOC); -afan Rabin Vincent wrote: On 6/11/06, Ahmed Abdel-Aliem [EMAIL PROTECTED] wrote: when i have array in the form of : Array ( [0] = 2 [ID] = 2 [1] = asdasd [CategoryName] = asdasd ) ) how can i make it in the form of : Array ( [ID] = 2 [CategoryName] = asdasd ) ) To remove a single element you can use unset: unset($arr[0]);. To remove all the elements with integer indices you could just loop, check, and unset those ones. What do you need to do this for? Your examples looks like arrays got from mysql_fetch_array. If this is so, using mysql_fetch_assoc() instead of that will get you only the associative array. Rabin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php