FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » how to assign a variable string from an array?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
how to assign a variable string from an array? [message #172451] Fri, 18 February 2011 19:54 Go to next message
richard is currently offline  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 Go to previous messageGo to next message
Luuk is currently offline  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 Go to previous message
richard is currently offline  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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: simple modal box to display info
Next Topic: Adult only
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 12:08:41 GMT 2024

Total time taken to generate the page: 0.02626 seconds