473,499 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exploding an array, kind of ...

I have an array as follows

$sounds = array();

$sounds['sound1'] = "fishes/1/sound.php";
$sounds['sound2'] = "fishes/2/sound.php";
$sounds['sound3'] = "fishes/3/sound.php";
$sounds['sound4] = "fishes/4/sound.php";
$sounds['sound5] = "fishes/5/sound.php";
$sounds['sound11] = "bears/1/sound.php";

etc etc......

What I want to be able to do have turn the above into this:

include ("sounds/fishes/1/sound.php");
include ("sounds/fishes/2/sound.php");
print ("<br>divider<br>");
include ("sounds/fishes/3/sound.php");
include ("sounds/fishes/4/sound.php");
print ("<br>divider<br>");
include ("sounds/fishes/5/sound.php");
include ("sounds/birds/1/sound.php");

etc etc

I'm totally clueless as to how I might acheive it, especially including the
"dividers" every two includes. Surely one of you clever folk gotta be able
to spoon feed it to me? ;)

Jul 17 '05 #1
9 1959
On Tue, 23 Mar 2004 16:46:55 +0000, mark wrote:
I'm totally clueless as to how I might acheive it, especially including the
"dividers" every two includes. Surely one of you clever folk gotta be able
to spoon feed it to me? ;)


no spoon feeding until you try harder. Some pointers, though:

Use

foreach($sounds as $key => $value){
}

and

the modulus operator (%) to determine if two rows have passed.
later....
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Website | http://www.wse.jhu.edu/newtnotes/

Jul 17 '05 #2
"Jeffrey Silverman" <je*****@jhu.edu> wrote in message
news:pa****************************@jhu.edu...

no spoon feeding until you try harder. Some pointers, though:

Use

foreach($sounds as $key => $value){
}

and

the modulus operator (%) to determine if two rows have passed.


thanks for the reply, but honestly I'm useless at PHP, any chance you could
tell me the answer really? pretty please?

Jul 17 '05 #3
mark wrote:
"Jeffrey Silverman" <je*****@jhu.edu> wrote in message
news:pa****************************@jhu.edu...

no spoon feeding until you try harder. Some pointers, though:

Use

foreach($sounds as $key => $value){
}

and

the modulus operator (%) to determine if two rows have passed.

thanks for the reply, but honestly I'm useless at PHP, any chance you could
tell me the answer really? pretty please?


You're not gonna get any better at PHP if everyone does all the work for
you. ;)

The foreach() will loop thru your $sounds array and pull the key/value
pairs and assign them to $key and $value. Then it's up to you to do
whatever you want with the two variables.

For the modulus (remainder of division), you could use a counter and
check if the counter is evenly divisible by 2 ($ctr % 2). If it is,
output your image/text/hr whatever. If not, continue the loop.

-Jay

Jul 17 '05 #4
"Jay Moore" <ad*****@isp.tld> wrote in message
news:Tg******************@twister.rdc-kc.rr.com...
mark wrote: You're not gonna get any better at PHP if everyone does all the work for
you. ;)

The foreach() will loop thru your $sounds array and pull the key/value
pairs and assign them to $key and $value. Then it's up to you to do
whatever you want with the two variables.

For the modulus (remainder of division), you could use a counter and
check if the counter is evenly divisible by 2 ($ctr % 2). If it is,
output your image/text/hr whatever. If not, continue the loop.


Excellent! I got it now and it works :) many thanks....

You don't happen to know how I can have the array come out upside down do
you too? pretty pretty please?
Jul 17 '05 #5
mark wrote (edited):
How can I have the array come out upside down?


http://www.php.net/array_reverse

Also look at all the other array functions. They're wonderful :)
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #6

"Pedro Graca" <he****@hotpop.com> wrote in message
news:c3*************@ID-203069.news.uni-berlin.de...
mark wrote (edited):
How can I have the array come out upside down?


http://www.php.net/array_reverse

Also look at all the other array functions. They're wonderful :)


thanks, If i try array_rand or revervse I get:

Warning: Wrong parameter count for array_rand on line 3:

:/
Jul 17 '05 #7


mark wrote:
"Jay Moore" <ad*****@isp.tld> wrote in message
news:Tg******************@twister.rdc-kc.rr.com...
mark wrote:


You're not gonna get any better at PHP if everyone does all the work for
you. ;)

The foreach() will loop thru your $sounds array and pull the key/value
pairs and assign them to $key and $value. Then it's up to you to do
whatever you want with the two variables.

For the modulus (remainder of division), you could use a counter and
check if the counter is evenly divisible by 2 ($ctr % 2). If it is,
output your image/text/hr whatever. If not, continue the loop.

Excellent! I got it now and it works :) many thanks....

You don't happen to know how I can have the array come out upside down do
you too? pretty pretty please?


http://us2.php.net/manual/en/function.arsort.php
http://us2.php.net/manual/en/function.krsort.php

Jul 17 '05 #8
mark wrote:
thanks, If i try array_rand or revervse I get:

Warning: Wrong parameter count for array_rand on line 3:


Post your code here. For me, both functions work as specified in the
manual.

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #9
"Jay Moore" <ad*****@isp.tld> wrote in message
news:1_******************@twister.rdc-kc.rr.com...

http://us2.php.net/manual/en/function.krsort.php


that works, although I have some problems because my array values are like
this 1, 11, 111 instead of 001, 011, 111
Jul 17 '05 #10

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

Similar topics

9
2105
by: Nathan Rose | last post by:
Here's my problem. I am reading from a text file using this: if (!file_exists($file)) { echo "Don't exist\n"; return false; } $fd = @fopen($file, 'r'); if (!is_resource($fd))
2
1984
by: JackM | last post by:
Let me attempt to explain my problem. I have a crude php script that takes a text list of songs that was generated by an mp3 list program and translates each entry into the form where they can be...
22
4569
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
204
12883
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
3
8877
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
24
4343
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
0
1919
by: helldiversafe-news | last post by:
Hi all, I will use a apache soap service with an .net c# client and have a problem with an complex array: <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope...
17
7211
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
7
2636
by: anklos | last post by:
Hi~! I met a problem on printing out a kind of hash array. i.e @array=(1,2,3,4,5,6); $array{$term}=1; diffent $i may contain diifernt $term(more than one term for each $i)
0
7007
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...
0
7174
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,...
1
6894
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
5470
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,...
1
4919
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...
0
3099
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...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.