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

  Como recuperar un archivo dañado NEW
  Des catégories qui disparaissent NEW
  How to reconcile several transactions at once NEW
  How can I Cc and/or Bcc a message with MaxBulk Mailer? NEW YouTube Video
  How to extract Contacts from Outlook Mac (OLM File) UPDATED Screenshot
  Does MaxBulk Mailer supports List-Unsubscribe ? Screenshot
  Trouble with mlm setup, 'The URL is not valid' error. Screenshot
  Problem with importing recipients Screenshot
  Why the iCash transaction amount column has disappeared Screenshot
  451 Error code Screenshot
  Problem sending email to Gmail recipients Screenshot
  What is the meaning of the recipient panel icons Screenshot
  How to create new projects in iCash Screenshot
  How to add transactions to iCash faster YouTube Video
  How to set BBEdit as the FTP Disk text editor?

Meet our new apps
AI support that never sleeps
Deploy an AI agent that learns your product, answers customers instantly, and lets one person handle what used to take an entire team. SoftDesk supports both email and chat with ready-to-install widgets.
SoftDesk
AI support that never sleeps
Learn more
Shared family finance made simple
Track income, expenses and everyday household spending in a simple, modern app designed for families, couples and shared budgets.
FamilyCash
Shared family finance made simple
Learn more
Fun learning that keeps kids engaged
Help children build skills through playful activities designed to make learning more enjoyable, motivating and rewarding.
KidBoost
Fun learning that keeps kids engaged
Learn more

 Last videos


🔐 Secured by Sectigo SSL | UptimeRobot - Site Loaded properly