473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

shortening an array

how does one shorten an array based on a key value.

Say I have this:

array("Car1"=>"Porsche","Car2"=>"Merc","Car3"=>"Fo rd","Car4"=>"Toyota");

and I want to pop "Car2" out of the array, leaving the rest of the elements.

array_pop appears to just pop the last element off the array - I want to pop
ANY element out of the array, thus shortening it.

Is there an easy way to do this, without resorting to iteration loops?

Jul 17 '05 #1
2 4876
kaptain kernel wrote:
how does one shorten an array based on a key value.

Say I have this:

array("Car1"=>"Porsche","Car2"=>"Merc","Car3"=>"Fo rd","Car4"=>"Toyota");

and I want to pop "Car2" out of the array, leaving the rest of the elements.
First thing I thought about was

unset($array_name['Car2']);

array_pop appears to just pop the last element off the array - I want to pop
ANY element out of the array, thus shortening it.

Is there an easy way to do this, without resorting to iteration loops?


You might want to check array_slice at
http://www.php.net/array_slice

--
..sig
Jul 17 '05 #2
Pedro Graca wrote:
kaptain kernel wrote:
how does one shorten an array based on a key value.

Say I have this:

array("Car1"=>"Porsche","Car2"=>"Merc","Car3"=>"Fo rd","Car4"=>"Toyota");

and I want to pop "Car2" out of the array, leaving the rest of the
elements.


First thing I thought about was

unset($array_name['Car2']);

That works fine Pedro. I didn't realise that you could unset a specific
array element.

Thanks!
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
4
by: Dariusz | last post by:
I have a guestbook on one of my sites where the entires are formatted to be x pixles in width. Now the text is input and output from a "blob" field from a database... but when people input long...
8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
3
by: ViperBlade | last post by:
Hi, i'm unsure of the versions of MySQL and PHP I'm using (although my webhost 'guarantees' the latest), but I don't think the answer would vary that much between versions. Now to the point: I'm...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.