six / solution 6.1
<?php
$fields = ["name", "nickname", "pronouns", "birthdate", "address", "email", "phone", "url", "socials", "created", "updated", "notes"];
$book = [];
// Sharon Wu
$book["Sharon Wu"] = [
"nickname" => ["woozie", "shar"],
"pronouns" => "she/they",
"birthdate" => 654359400,
"address" => [
"home" => "126 Main Street\nPhiladelphia, PA 19127\nUnited States of America",
],
"email" => ["work" => "[email protected]"],
"phone" => ["work" => "+1.234.567.8901"],
"url" => [
"work" => "https://php.org/sharon.wu",
],
"socials" => [
"instagram" => "@php.sharon.wu",
],
"created" => 3155772600,
"updated" => 3155772600,
"notes" => "",
];
// Lori Kim
$book["Lori Kim"] = [
"nickname" => ["lor", "pookie"],
"pronouns" => "she/her",
"birthdate" => 774196200,
"address" => [],
"email" => ["work" => "[email protected]"],
"phone" => ["work" => "+1.234.567.8901"],
"url" => [
"work" => "https://php.org/lori.kim",
],
"socials" => [
"instagram" => "@php.lori.kim",
],
"created" => 3155772600,
"updated" => 3155772600,
"notes" => "",
];
// Disha Wish
$book["Disha Wish"] = [
"nickname" => ["star"],
"pronouns" => "she/they",
"birthdate" => 866471400,
"address" => [],
"email" => [
"work" => "[email protected]",
"home" => "[email protected]",
],
"phone" => ["work" => "+1.234.567.8901"],
"url" => [
"work" => "https://php.org/disha.wish",
],
"socials" => [
"instagram" => "@php.disha.wish",
],
"created" => 3155772600,
"updated" => 3155772600,
"notes" => "",
];
// Emily Barnes
$book["Emily Barnes"] = [
"nickname" => ["adoorable", "stable"],
"pronouns" => "they/them",
"birthdate" => 1075476600,
"address" => [
"home" => "6200 University Boulevard\nVancouver, BC V6T 1Z4\nCanada",
],
"email" => [
"work" => "[email protected]",
"home" => "[email protected]",
],
"phone" => ["work" => "+1.234.567.8901"],
"url" => [
"work" => "https://php.org/emily.barnes",
],
"socials" => [
"instagram" => "@php.emily.barnes",
],
"created" => 3155772600,
"updated" => 3155772600,
"notes" => "",
];
// Evelyn Silk
$book["Evelyn Silk"] = [
"nickname" => ["smoothie", "eve"],
"pronouns" => "they/she",
"birthdate" => 630516600,
"address" => [
"home" => "1 rue Victor Cousin\n75005 Paris\nFrance",
],
"email" => [
"work" => "[email protected]",
"home" => "[email protected]",
],
"phone" => ["work" => "+33.234.567.8901"],
"url" => [
"work" => "https://php.org/evelyn.silk",
],
"socials" => [
"instagram" => "@php.evelyn.silk",
],
"created" => 3155772600,
"updated" => 3155772600,
"notes" => "",
];
// Ava Machs
$book["Ava Machs"] = [
"nickname" => ["pads"],
"pronouns" => "she/they",
"birthdate" => 600535800,
"address" => [
"home" => "99 Shangda Road\nBaoshan District, Shanghai 200444\nChina",
],
"email" => [
"work" => "[email protected]",
"home" => "[email protected]",
],
"phone" => ["work" => "+86.234.567.8901"],
"url" => [
"work" => "https://php.org/ava.machs",
],
"socials" => [
"instagram" => "@php.ava.machs",
],
"created" => 3155772600,
"updated" => 3155772600,
"notes" => "",
];
// Harper Wren
$book["Harper Wren"] = [
"nickname" => ["wrinkle", "birdie"],
"pronouns" => "they/them",
"birthdate" => 946567800,
"address" => [
"home" => "80 Wellington Street\nOttawa, ON K1A 0A2\nCanada",
],
"email" => [
"work" => "[email protected]",
"home" => "[email protected]",
],
"phone" => ["work" => "+1.234.567.8901"],
"url" => [
"work" => "https://php.org/harper.wren",
],
"socials" => [
"instagram" => "@php.harper.wren",
],
"created" => 3155772600,
"updated" => 3155772600,
"notes" => "",
];
// Mia Lynx
$book["Mia Lynx"] = [
"nickname" => ["furry"],
"pronouns" => "they/it",
"birthdate" => 1005147000,
"address" => [
"home" => "Nueva Tajamar 481\nTorre Norte, Las Condes, Santiago\nChile",
],
"email" => [
"work" => "[email protected]",
"home" => "[email protected]",
],
"phone" => ["work" => "+56.234.567.8901"],
"url" => [
"work" => "https://php.org/mia.lynx",
],
"socials" => [
"instagram" => "@php.mia.lynx",
],
"created" => 3155772600,
"updated" => 3155772600,
"notes" => "",
];
// Sophie Koh
$book["Sophie Koh"] = [
"nickname" => ["kodiak"],
"pronouns" => "she/they",
"birthdate" => 1049470200,
"address" => [
"home" => "1 Zmora Street\nJerusalem, 9515701\nIsrael",
],
"email" => ["work" => "[email protected]"],
"phone" => ["work" => "+972.234.567.8901"],
"url" => [
"work" => "https://php.org/sophie.koh",
],
"socials" => [
"instagram" => "@php.sophie.koh",
],
"created" => 3155772600,
"updated" => 3155772600,
"notes" => "",
];
// Isla White
$book["Isla White"] = [
"nickname" => ["scottie", "black"],
"pronouns" => "she/her",
"birthdate" => 1062426600,
"address" => [],
"email" => ["work" => "[email protected]"],
"phone" => ["work" => "+1.234.567.8901"],
"url" => [
"work" => "https://php.org/isla.white",
],
"socials" => [
"instagram" => "@php.isla.white",
],
"created" => 3155772600,
"updated" => 3155772600,
"notes" => "",
];
// clean entries
foreach ($book as &$entry) {
foreach ($fields as $field) {
if (isset($entry[$field])) {
$i = &$entry[$field];
if ($field == "name" || $field == "pronouns" || $field == "notes") {
$i = trim($i);
$field == "name" && ($i = mb_convert_case($i, MB_CASE_TITLE));
$field == "pronouns" && ($i = mb_convert_case($i, MB_CASE_LOWER));
}
if ($field == "nickname" || $field == "address" || $field == "email" || $field == "phone" || $field == "url" || $field == "socials") {
$i = array_change_key_case($i, CASE_LOWER);
foreach ($i as &$v) {
$v = trim($v);
}
if ($field == "nickname") {
foreach ($i as &$v) {
$v = mb_convert_case($v, MB_CASE_LOWER);
}
}
if ($field == "address") {
foreach ($i as &$v) {
$v = mb_convert_case($v, MB_CASE_TITLE);
}
}
if ($field == "email") {
foreach ($i as &$v) {
$v = mb_convert_case($v, MB_CASE_LOWER);
$v = str_replace([" ", "\t", "\n"], "", $v);
}
}
}
}
}
}
// unset variables passed by reference before reusing them
unset($i, $entry, $v);
// output tab-delimited table
foreach ($fields as $field) {
print_r($field . "\t");
}
print_r("\n");
date_default_timezone_set("America/Vancouver");
foreach ($book as $entry) {
foreach ($fields as $field) {
if (isset($entry[$field])) {
$i = $entry[$field];
($field == "name" || $field == "pronouns" || $field == "notes") && print_r(str_replace("\n", ", ", $i));
($field == "birthdate" || $field == "created" || $field == "updated") && print_r(date("Y.m.d h.i.s", $i));
$field == "nickname" && print_r(implode(", ", $i));
if ($field == "address" || $field == "email" || $field == "phone" || $field == "url" || $field == "socials") {
$build = [];
foreach ($i as $k => $v) {
$build[] = $k . " - " . str_replace("\n", ", ", $v);
}
print_r(implode(", ", $build));
}
}
print_r("\t"); // after each element
}
print_r("\n"); // after each entry
}