473,414 Members | 1,626 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,414 software developers and data experts.

Problem with multidimensional array

Hi,

I've got a multidimensional array which looks like this:
$data[] = array('nname' => 'Auerbach', 'vname' => 'Berthold', 'uid' => 20);
$data[] = array('nname' => 'Bloch', 'vname' => 'Ernst', 'uid' => 24);
$data[] = array('nname' => 'Shaw', 'vname' => 'George Bernard', 'uid' =>19);
$data[] = array('nname' => 'Wilde', 'vname' => 'Oscar', 'uid' => 12);
$data[] = array('nname' => 'Wilder', 'vname' => 'Thornton', 'uid' => 38);
........

And I've got the following code, which splitts the last names (nname) =>
$az = array ('ABC','DEF','GHI','JKL','MNO','PQR','STU','VWX',' YZ');
$x = 0;
foreach($data as $name) {
if(substr($name[nname], 0,1) == substr($az[$x], 0,1) ||
substr($name[nname], 0,1) == substr($az[$x], 1,2) || substr($name[nname],
0,1) == substr($az[$x], 2,3)) {
if($az[$x] != $alt) {
echo "<br /><big><b>".$az[$x]."</b></big><br />";
$alt = $az[$x];
$x = $x + 1;

}
}
echo $name[nname].', '.$name[vname]."<br />";
}

You can see the problem here:
http://inside.eventshooters.com/typo...e/pi1/test.php

Kant, Immanuel => GHI
Waggerl, Karl Heinrich => STU
Wilde, Oscar => STU
Wilder, Thornton => STU

Where is my problem?
Please help me!
Many thanks!

georg
Jul 17 '05 #1
9 2184
Georg Ringer said the following on 17/06/2005 14:34:
Hi,

I've got a multidimensional array which looks like this:
$data[] = array('nname' => 'Auerbach', 'vname' => 'Berthold', 'uid' => 20);
$data[] = array('nname' => 'Bloch', 'vname' => 'Ernst', 'uid' => 24);
$data[] = array('nname' => 'Shaw', 'vname' => 'George Bernard', 'uid' =>19);
$data[] = array('nname' => 'Wilde', 'vname' => 'Oscar', 'uid' => 12);
$data[] = array('nname' => 'Wilder', 'vname' => 'Thornton', 'uid' => 38);
.......

And I've got the following code, which splitts the last names (nname) =>
$az = array ('ABC','DEF','GHI','JKL','MNO','PQR','STU','VWX',' YZ');
$x = 0;
foreach($data as $name) {
if(substr($name[nname], 0,1) == substr($az[$x], 0,1) ||
substr($name[nname], 0,1) == substr($az[$x], 1,2) || substr($name[nname],
0,1) == substr($az[$x], 2,3)) {
if($az[$x] != $alt) {
echo "<br /><big><b>".$az[$x]."</b></big><br />";
$alt = $az[$x];
$x = $x + 1;

}
}
echo $name[nname].', '.$name[vname]."<br />";
}

You can see the problem here:
http://inside.eventshooters.com/typo...e/pi1/test.php

Kant, Immanuel => GHI
Waggerl, Karl Heinrich => STU
Wilde, Oscar => STU
Wilder, Thornton => STU

Where is my problem?
Please help me!


Check the syntax for substr().
http://www.php.net/substr

--
Oli
Jul 17 '05 #2
aparently the line " echo $name[nname].', '.$name[vname]."<br />";"
it's outside the if statement :S

Jul 17 '05 #3
> aparently the line " echo $name[nname].', '.$name[vname]."<br />";"
it's outside the if statement :S


but why is the record Kant, Immanuel at the wrong place??? because of this
you mentioned?

georg
Jul 17 '05 #4
> Check the syntax for substr().
http://www.php.net/substr


What is not correct?
Jul 17 '05 #5
Georg Ringer said the following on 17/06/2005 15:04:
Check the syntax for substr().
http://www.php.net/substr

What is not correct?

The third argument should be *length*, not end position.

--
Oli
Jul 17 '05 #6
sorry. it has nothing to do with the if statement.
u hve a bad syntax in substr().

the last parameter should always be 1 (in this case that is)
substr($az[$x], <N>,1)

Jul 17 '05 #7
"saintexupery" <cr***************@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
aparently the line " echo $name[nname].', '.$name[vname]."<br />";"
it's outside the if statement :S


Which is ugly in itself... try:

echo "$name[nname], $name[vname]<br/>";

instead...

Norm
--
FREE Avatar hosting at www.easyavatar.com

Jul 17 '05 #8
Norman Peelman <np******@cfl.rr.com> wrote:
aparently the line " echo $name[nname].', '.$name[vname]."<br />";"


Which is ugly in itself... try:

echo "$name[nname], $name[vname]<br/>";


Which is considered bad code:
http://www.php.net/manual/en/languag...es.array.donts
Jul 17 '05 #9
"Daniel Tryba" <pa**********@invalid.tryba.nl> wrote in message
news:42***********************@news6.xs4all.nl...
Norman Peelman <np******@cfl.rr.com> wrote:
aparently the line " echo $name[nname].', '.$name[vname]."<br />";"


Which is ugly in itself... try:

echo "$name[nname], $name[vname]<br/>";


Which is considered bad code:

http://www.php.net/manual/en/languag...es.array.donts

Look alittle farther down the page under 'More examples to demonstrate
this fact:' and you will see:

// The following is okay as it's inside a string. Constants are not
// looked for within strings so no E_NOTICE error here
print "Hello $arr[fruit]"; // Hello apple

// With one exception, braces surrounding arrays within strings
// allows constants to be looked for
print "Hello {$arr[fruit]}"; // Hello carrot
print "Hello {$arr['fruit']}"; // Hello apple

--- end ---

Norman
---
FREE Avatar Hosting at www.easyavatar.com
Jul 17 '05 #10

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

Similar topics

5
by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would...
9
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
1
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
1
by: Chuy08 | last post by:
If I have a multidimensional array like the following: Array $records =Array 0 = 30 year, 6.0; 1 = 30 year, 6.0; 2 = Pay Option, 1.0; 3 = Pay Option, 1.0; How could I flatten this to...
5
by: LittleCake | last post by:
Hi All, I have a multidimensional array where each sub-array contains just two entries, which indicates a relationship between those two entries. for example the first sub-array: =Array ( =30...
4
Jezternz
by: Jezternz | last post by:
First of all I am open to any suggestions and advice. If a javscript multidimensional array is a bad way to do this please say so. I considered XML but I wondered if this would be a bad idea as it...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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
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
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...
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...
0
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...

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.