473,398 Members | 2,525 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,398 software developers and data experts.

Array Question I am stuck on this one



Lets say you have a array declared like this
<?php

$Array=array("Drum & Bass","Jungle","House","Techno","Hip Hop");

?>

but what i want do do is somehow using a for loop to remove items in the
array. The items i want to remove are 0,2,4 or just 2,5. Deleting a item
in the array has to be flexible at which item to delete.
I appreciate anybody helps me on this thanks very much :)

Jul 17 '05 #1
4 1365
To remove item $Array[4]:

unset($Array[4]);

Note that this will not re-index the array continuously -- you'll just
have buckets with null values.

If you want to re-index the array, use:

array_merge($Array);

Jul 17 '05 #2

Thanks but what if this were the case

<?php

//Items in Array One
$Array=array("Drum & Bass","Jungle","House","Techno","Hip Hop");

//Remove Array

$Array_removeItems=array("0","2","4");

?>

How would i remove items in Array One with the items specified in the other
array. Note in Array_removeItems the values can change also.

Thanks a million :)

Hello ZeldorBlat,
To remove item $Array[4]:

unset($Array[4]);

Note that this will not re-index the array continuously -- you'll just
have buckets with null values.

If you want to re-index the array, use:

array_merge($Array);

Jul 17 '05 #3
//Items in Array One
$Array=array("Drum & Bass","Jungle","House","Techno","Hip Hop");

//Remove Array
$Array_removeItems=array("0","2","4");

for($i = 0; $i < count($Array_removeItems); $i++)
unset($Array[$Array_removeItems[$i]]);

Jul 17 '05 #4
ZeldorBlat wrote:
//Items in Array One
$Array=array("Drum & Bass","Jungle","House","Techno","Hip Hop");

//Remove Array
$Array_removeItems=array("0","2","4");

for($i = 0; $i < count($Array_removeItems); $i++)
unset($Array[$Array_removeItems[$i]]);


or

foreach ($Array_removeItems as $i)
unset($Array[$i]);

(still surprised by the number of times I see this C-style for loop
instead of a foreach loop)
Jul 17 '05 #5

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

Similar topics

8
by: Bob Bedford | last post by:
I've this structure in a XML file: Type Model Detail Datas Datas Datas Datas /Detail Detail
7
by: ritchie | last post by:
Hi all, I am new to this group and I have question that you may be able to help me with. I am trying to learn C but am currently stuck on this. First of all, I have a function for each sort...
30
by: questions? | last post by:
say I have a structure which have an array inside. e.g. struct random_struct{ char name; int month; } if the array is not intialized by me, in a sense after I allocated a
7
by: Bhadan | last post by:
Hello, I have several jagged arrays which have been sorted. I'm trying to find the median of each array. Any tips appreciated. TIA. Bhads.
5
by: benyboy | last post by:
hi, after hours of staring at my computer screen, and browsing through various internet forums i am totally stuck! I have created the following array which reads from an input file the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.