php: build a HTML ul - li list from an associative array
2019-10-01
IN1, 2019-10-01 00:00:00
IN1, 2023-04-10 14:16:30


Q: how to build an <ul>..<li> list on an array with php?

A: use the recursive function below for creation.

/**
 * @param array $aData
 * @return string $sMarkup Markup <ul>..<li> List
 */
function buildMarkupListTree($aData)
{
    if (false === is_array($aData))
    {
        return '';
    }

    $sMarkup = '<ul>';

    foreach ($aData as $sKey => $mValue)
    {
        $sMarkup.= '<l […]

php: beautify var_export
2019-09-24
IN1, 2019-09-24 00:00:00
IN1, 2023-04-10 14:16:30


Die Ausgabe von var_export() aufgehübscht.

Mit Rückgabe von array(..) als Array Indikator

// prettify var_dump array
$sExport = var_export($mData, true);
$sExport = preg_replace("/^([ ]*)(.*)/m", '$1$1$2', $sExport);
$aData = preg_split("/\r\n|\n|\r/", $sExport);
$aData = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [NULL, ')$1', ' => array('], $aData);
$sExport = join(PHP_EOL […]


This website uses Cookies to provide you with the best possible service. Please see our Privacy Policy for more information. Click the check box below to accept cookies. Then confirm with a click on "Save".