how to assign a variable string from an array? [message #172451] |
Fri, 18 February 2011 19:54 |
|
richard
Messages: 213 Registered: June 2013
Karma: 0
|
Senior Member |
|
|
$a=array(1=>
array("John","123 Adams","555-0102","electrician"),
array("Bob","234 Quincy","555-7788","barber"),
array("Charles","756 Capitol","555-9090","teacher")
)
<a href="#">John</a>
<a href="#">Bob</a>
<a href="#">Charles</a>
Given that a popup box will appear showing each of the individuals
information from the array, how does one go about doing that?
echo $a[1][1]
would print out that item only in all three cases.
I need it to be like
echo $a[x][1]
Where x can be either of the item indexes.
I have looked at dozens of sites that talk about arrays, but none that I
have seen show how to do this. One site briefly mentioned the extract()
function but was rather lame on an explanation.
|
|
|
Re: how to assign a variable string from an array? [message #172452 is a reply to message #172451] |
Fri, 18 February 2011 20:04 |
Luuk
Messages: 329 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 18-02-11 20:54, richard wrote:
> $a=array(1=>
> array("John","123 Adams","555-0102","electrician"),
> array("Bob","234 Quincy","555-7788","barber"),
> array("Charles","756 Capitol","555-9090","teacher")
> )
// John,Bob, Charles
echo "Names: \n<br>";
for ($x=1; $x<count($a[1]); $x++ ) {
echo $a[$x][0]."\n<br>";
}
// Adresses
echo "Addresses: \n<br>";
for ($x=1; $x<count($a[1]); $x++ ) {
echo $a[$x][1]."\n<br>";
}
--
Luuk
|
|
|
Re: how to assign a variable string from an array? [message #172453 is a reply to message #172452] |
Fri, 18 February 2011 20:12 |
|
richard
Messages: 213 Registered: June 2013
Karma: 0
|
Senior Member |
|
|
On Fri, 18 Feb 2011 21:04:18 +0100, Luuk wrote:
> On 18-02-11 20:54, richard wrote:
>> $a=array(1=>
>> array("John","123 Adams","555-0102","electrician"),
>> array("Bob","234 Quincy","555-7788","barber"),
>> array("Charles","756 Capitol","555-9090","teacher")
>> )
>
> // John,Bob, Charles
> echo "Names: \n<br>";
> for ($x=1; $x<count($a[1]); $x++ ) {
> echo $a[$x][0]."\n<br>";
> }
>
> // Adresses
> echo "Addresses: \n<br>";
> for ($x=1; $x<count($a[1]); $x++ ) {
> echo $a[$x][1]."\n<br>";
> }
Thanks.
I think I see what you're doing. Reassigning the main array values into an
array you call $x then using that array as the base.
http://1littleworld.net/modalbox/
As I have the text shown in <ul> format, how would I go about assigning a
value to each of the names so that a for loop would not be necessary?
Or would the loop be better?
I would need some way of matching up the linked item with what is in the
array.
|
|
|