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

Home » Imported messages » comp.lang.php » PHP Array check
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
PHP Array check [message #173812] Fri, 06 May 2011 21:25 Go to next message
Naytee is currently offline  Naytee
Messages: 1
Registered: May 2011
Karma: 0
Junior Member
This may be a very dumb question to you guys, but I am a PHP
beginner. I have a PHP link that I would like to contain in an array,
with URLs and link titles being the contained data. After researching
arrays a little, I understand that something like

$thenumbers = array('ONE', 'dos', 'three', '4');

foreach ($thenumbers as $thenumber) {
echo $thenumber.', ';
}

would return "ONE, dos, three, 4, " as I added a separating comma.
However, I want two variables to appear inside of my echo line. I
shall break this down into two parts.

1) Would array('MyURL' => 'MyText', 'MySecondURL' => 'MySecondText')
be a valid array to insert into '<a href=THE LINK>THE TEXT</a>'?

2) a) If so, how would I declare each variable in the same way I did
before?

2) b) If not, how would I write my array? I want to avoid writing two
arrays where possible.

Please remember, I am a beginner at PHP, I am just learning, so please
be patient ant explain everything to me as simple as possible.
Re: PHP Array check [message #173814 is a reply to message #173812] Fri, 06 May 2011 23:43 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/6/2011 5:25 PM, Naytee wrote:
> This may be a very dumb question to you guys, but I am a PHP
> beginner. I have a PHP link that I would like to contain in an array,
> with URLs and link titles being the contained data. After researching
> arrays a little, I understand that something like
>
> $thenumbers = array('ONE', 'dos', 'three', '4');
>
> foreach ($thenumbers as $thenumber) {
> echo $thenumber.', ';
> }
>
> would return "ONE, dos, three, 4, " as I added a separating comma.
> However, I want two variables to appear inside of my echo line. I
> shall break this down into two parts.
>
> 1) Would array('MyURL' => 'MyText', 'MySecondURL' => 'MySecondText')
> be a valid array to insert into '<a href=THE LINK>THE TEXT</a>'?
>

The array definition would be correct.

> 2) a) If so, how would I declare each variable in the same way I did
> before?
>

You need the key and the value, i.e.

foreach($thenumbers as $key=>$value)


> 2) b) If not, how would I write my array? I want to avoid writing two
> arrays where possible.
>
> Please remember, I am a beginner at PHP, I am just learning, so please
> be patient ant explain everything to me as simple as possible.

A great place to start is with the official doc. For instance, see
http://us3.php.net/manual/en/control-structures.foreach.php

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How stupid ARE people?
Next Topic: Re: Hello Friends
Goto Forum:
  

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

Current Time: Fri Nov 22 18:20:03 GMT 2024

Total time taken to generate the page: 0.02122 seconds