473,765 Members | 1,909 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<b r>");
include ("sounds/fishes/3/sound.php");
include ("sounds/fishes/4/sound.php");
print ("<br>divider<b r>");
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 1982
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.ed u> 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.ed u> wrote in message
news:pa******** *************** *****@jhu.edu.. .

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

Use

foreach($soun ds 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.tl d> wrote in message
news:Tg******** **********@twis ter.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.tl d> wrote in message
news:Tg******** **********@twis ter.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.tl d> wrote in message
news:1_******** **********@twis ter.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
2125
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
2016
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 inserted into my mySQL database in the proper fields although it is currently being written to another text file because of the problem I have below. The lines from the mp3 text file will look like this: Al Green - The Supreme Al Green - 01 -...
22
4642
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 month I had enough of extra proof that the cat doesn't hount mice anymore in more and more situations. And the surrent sicretisme among array and hash is the base for it. I summarized all points in this article:...
204
13075
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 = {0,1,2,4,9};
3
8899
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 Me.ListBoxPerson.Items.AddRange(ary)
24
4394
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 we covered was within the last week of the class and all self taught. Our prof gave us an example of a Java method used to remove elements from an array: public void searchProcess() { int outIt=0;
0
1943
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 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body>
17
7253
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 to show the array data to the end user. Can I do that? How?
7
2652
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
9393
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
10153
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
9946
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,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8830
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6646
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3921
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
3530
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.