473,560 Members | 2,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with multidimensiona l array

Hi,

I've got a multidimensiona l 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','G HI','JKL','MNO' ,'PQR','STU','V WX','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>".$a z[$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 2194
Georg Ringer said the following on 17/06/2005 14:34:
Hi,

I've got a multidimensiona l 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','G HI','JKL','MNO' ,'PQR','STU','V WX','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>".$a z[$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
"saintexupe ry" <cr************ ***@gmail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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.r r.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**********@i nvalid.tryba.nl > wrote in message
news:42******** *************** @news6.xs4all.n l...
Norman Peelman <np******@cfl.r r.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
6742
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 clearly be the most efficient way to do it, but it only works on a copy of the original array and not the original (which is counter intuitive in my...
9
4321
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 vbscript reads the database and populates a listbox on the page with the first field from each record in the recordset. This works fine. - User...
9
6656
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 function (which was translated from Fortran code), among other heinous and numerous declarations, is this bit: static float bbuff; static int...
1
8227
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 RankException. But the MSDN documentation says: When copying between multidimensional arrays, the array
10
12182
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 help do the most basic things. One of the "basic" things I haven't been able to find out how to do is how to delete an item from a...
1
9768
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 achieve an array that only has unique Product
5
2305
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 =31 )
4
2501
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 would be slower for jsp to handel. Okay here is an example of my multidimensional array (only part of it)(bottom of the post). It works fine I can...
9
4484
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 function: x = new int;
0
7635
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...
0
7556
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...
0
7845
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. ...
0
7921
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...
0
5176
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...
0
3607
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...
0
3589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2050
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
0
882
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.