Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #1447 > unrolled thread
| Started by | Naytee <nayteebunn@gmail.com> |
|---|---|
| First post | 2011-05-06 14:25 -0700 |
| Last post | 2011-05-06 19:43 -0400 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.php
PHP Array check Naytee <nayteebunn@gmail.com> - 2011-05-06 14:25 -0700
Re: PHP Array check Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-06 19:43 -0400
| From | Naytee <nayteebunn@gmail.com> |
|---|---|
| Date | 2011-05-06 14:25 -0700 |
| Subject | PHP Array check |
| Message-ID | <249d2263-ac49-4b9d-a3a2-514700b5eec7@f2g2000yqf.googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-05-06 19:43 -0400 |
| Message-ID | <iq2133$e9l$1@dont-email.me> |
| In reply to | #1447 |
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@attglobal.net
==================
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web