Jump to content

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>';
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.