Support

Home Products Downloads News Store Support

Stan's Blog

Array of arrays

How to use Maxprog products Maxprog's Blog

Compatible with MS Windows Compatible with MacOS


Array of arrays

Topics

In PHP you can use arrays of arrays. This is a very convenient way to store data for later manipulation. This is an example of an array with 2 web records:

$urls = array();

$url = array( "Full" => "[URL http://www.maxprog.com]Maxprog[/URL]",
              "URL"  => "http://www.maxprog.com",
              "Text" => "Maxprog"
              );
$urls[] = $url;

$url = array( "Full" => "[URL http://www.apple.com]Apple[/URL]",
              "URL"  => "http://www.apple.com",
              "Text" => "Apple"
              );
$urls[] = $url;


You can format the output this way:

foreach( $urls as $url ){
    echo "<a href=\"". $url['URL'] . "\">" . $url['Text'] . "</a><br>\n";
}


The result will be:

<a href="http://www.maxprog.com">Maxprog</a><br>
<a href="http://www.apple.com">Apple</a><br>


You can try this code here.

And in order to get the keys and values:

foreach( $urls as $url ){
    foreach( $url as $key => $value ){
        echo "{$key} => {$value}\n";
    }
    echo "\n";
}


The result will be:

Full => [URL http://www.maxprog.com]Maxprog[/URL]
URL  => http://www.maxprog.com
Text => Maxprog

Full => [URL http://www.apple.com]Apple[/URL]
URL  => http://www.apple.com
Text => Apple


You can try this code here. I have used this approach lately in new Maxprog Knowledge-base system, in order to format parts of the messages depending on their types.


Stan Busk - Software Engineer
at www.maxprog.com










Recent questions from our users
  Google ending support for less secure apps NEW YouTube Video
  How to add social networks icons to my message UPDATED Screenshot
  How do I set up an unsubscribe link UPDATED Screenshot
  How to export several lists into to a single file UPDATED Screenshot
  Why do I get timeouts when testing given addresses UPDATED Screenshot
  What are the Zoho mail settings for MaxBulk Mailer? UPDATED Screenshot
  iCash has become slow over time UPDATED Screenshot
  Emails sent but not received UPDATED Screenshot
  HTML Email is received empty UPDATED Screenshot
  How to use an alternative text when a tag value is empty UPDATED Screenshot
  Email Bounce Handler no longer works with Gmail UPDATED Screenshot
  Is Maxprog software ready for the Apple ARM processor? Screenshot
  Is Maxprog software prepared for Windows 11? Screenshot
  Is Maxprog software prepared for macOS 12 Monterey? Screenshot
  Mail rejected as SPAM Screenshot

▾ Last videos, Online events and Q&A Sessions ▾

▾ Last customer reviews ▾


Did you like this post?


🔐 Secured by Comodo SSL | UptimeRobot - Site Loaded properly