Jump to content

[SOLVED] Creating Buttons and Lables with two arrays


Pjack125

Recommended Posts

I am trying to create a buttons by getting the information from two arrays one for the buttons URLS and the other one is for the buttons lable. How would i go about doing so.

 

so far i have

$array1 = array("lable1","lable2","lable3");
$array2 = array("URL1","URL2","URL3");

I tried using for for each but that gave me issues what is the most effective way to achieve this?

for

 

<?php
$cnt = count($array1);
for ($i=0; $i<$cnt; $i++) {
    echo '<a href="' . $array1[$i].'">' . $array2[$i] . '</a>';
}
?>

 

Something like that should work.

 

Edit:

Or make it associative array:

<?php
$arrays = array("lable1"=>"URL1","lable2"=>"URL2", "lable3" => "URL3");

foreach ($arrays as $key => $val) {
    echo '<a href="' . $val.'">' . $key . '</a>';
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.