473,806 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

shortening an array

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

Say I have this:

array("Car1"=>" Porsche","Car2" =>"Merc","Car3" =>"Ford","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 4910
kaptain kernel wrote:
how does one shorten an array based on a key value.

Say I have this:

array("Car1"=>" Porsche","Car2" =>"Merc","Car3" =>"Ford","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_na me['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" =>"Ford","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_na me['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
575
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 print_r cmd any suggestions would be great. Thanks much Todd //avShed array Array ( => Array ( => 1 => 08:00 ) => Array ( => 1 => 08:05 ) => Array ( => 1 => 08:10 ) => Array ( => 1 => 08:15 ) => Array ( => 1 => 08:20 ) => Array...
15
5198
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
1524
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 URL's into their entries, the formatting of the page is ruined. Can anyone suggest a way for PHP to "read through" the text and substitute a URL with a short text link, but still keeping the URL so it's clickable? From my observations, the URL's...
8
3486
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( "name", "title", "reports to user id", "start date in the format: mm/dd/yyyy" ) ); How can I display this hierarchy in simple nested <li> tags in the most
12
55576
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 also removed) So far I have (val is value, ar is array, returns new array):
8
10235
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 it is assigned a text literal?? HOW can I change the array value to upper case then? What other method exists for arrays? Ex: var GridArrayName1 = new Array(); GridArrayName1 = new Array ('test-value'); GridArrayName1 = GridArrayName1...
58
10189
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 code... TCHAR myArray; DoStuff(myArray);
35
6683
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
1330
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 trying to echo text fetched from a database into a 128px width column, which doens't always fit. I'd like to know how to shorten the results of an array using '...'s like: 'Amer...' or 'Urag...' instead of 'America' or 'Uraguay'. Thank you,...
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.