PHP code example of ngomafortuna / list-formatter

1. Go to this page and download the library: Download ngomafortuna/list-formatter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ngomafortuna / list-formatter example snippets


ListToString::get($array, 'array_key');
ListToString::getWithLink($array, ['array_key', 'array_key'], 'url');

Order::get($array, 'array_key');
Order::getReverse($array, 'array_key');

ToListType::toObject($array);
ToListType::toArray($object);

use Ngomafortuna\ListFormatter\ListToString;
use Ngomafortuna\ListFormatter\Order;
use Ngomafortuna\ListFormatter\ToListType;

$arrayLIst = [
    ['title' => 'Socieda', 'slug'=> 'sociedade','date' => '2024-76-06'],
    ['title' => 'Vestimentas', 'slug'=> 'vestimentas', 'date' => '2024-06-06'],
    ['title' => 'Cultura', 'slug'=> 'cultura','date' => '2025-06-06'],
];

$list = ListToString::get($arrayLIst, 'title');
$list_with_link = ListToString::getWithLink($arrayLIst, ['title', 'slug'], 'https://www.minharosa.ao');

var_dump($list, $list_with_link);

$order = Order::get($arrayLIst, 'title');
$order_reverse = Order::getReverse($arrayLIst, 'title');

var_dump($order, $order_reverse);

$conv_to_object = ToListType::toObject($arrayLIst);

// create object to convert
$listObj = [];
foreach($arrayLIst as $item) {
    $objModel = new \stdClass();
    $objModel->title = $item['title']; $objModel->slug =  $item['slug']; $objModel->date = $item['date']; $listObj[] = $objModel;
}
$listObj = (object) $listObj;
$conv_to_array = ToListType::toArray($listObj);

var_dump($conv_to_object, $conv_to_array);
shell
array(3) {
  [0]=>
  array(3) {
    ["title"]=>
    string(7) "Cultura"
    ["slug"]=>
    string(7) "cultura"
    ["date"]=>
    string(10) "2025-06-06"
  }
  [1]=>
  array(3) {
    ["title"]=>
    string(7) "Socieda"
    ["slug"]=>
    string(9) "sociedade"
    ["date"]=>
    string(10) "2024-76-06"
  }
  [2]=>
  array(3) {
    ["title"]=>
    string(11) "Vestimentas"
    ["slug"]=>
    string(11) "vestimentas"
    ["date"]=>
    string(10) "2024-06-06"
  }
}

array(3) {
  [0]=>
  array(3) {
    ["title"]=>
    string(11) "Vestimentas"
    ["slug"]=>
    string(11) "vestimentas"
    ["date"]=>
    string(10) "2024-06-06"
  }
  [1]=>
  array(3) {
    ["title"]=>
    string(7) "Socieda"
    ["slug"]=>
    string(9) "sociedade"
    ["date"]=>
    string(10) "2024-76-06"
  }
  [2]=>
  array(3) {
    ["title"]=>
    string(7) "Cultura"
    ["slug"]=>
    string(7) "cultura"
    ["date"]=>
    string(10) "2025-06-06"
  }
}