base arr - PHP Online
Form of PHP Sandbox
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of base arr.php
- <?php
- $users = [
- [
- "id" => 1,
- "name" => "Leanne Graham",
- "username" => "Bret",
- "address" => [
- "street" => "Kulas Light",
- "suite" => "Apt. 556",
- "city" => "Gwenborough",
- "zipcode" => "92998-3874",
- "geo" => [
- "lat" => "-37.3159",
- "lng" => "81.1496"
- ]
- ],
- "phone" => "1-770-736-8031 x56442",
- "website" => "hildegard.org",
- "company" => [
- "name" => "Romaguera-Crona",
- "catchPhrase" => "Multi-layered client-server neural-net",
- "bs" => "harness real-time e-markets"
- ]
- ],
- [
- "id" => 2,
- "name" => "Ervin Howell",
- "username" => "Antonette",
- "address" => [
- "street" => "Victor Plains",
- "suite" => "Suite 879",
- "city" => "Wisokyburgh",
- "zipcode" => "90566-7771",
- "geo" => [
- "lat" => "-43.9509",
- "lng" => "-34.4616"
- ]
- ],
- "phone" => "010-692-6593 x09125",
- "website" => "anastasia.net",
- "company" => [
- "name" => "eckow-Crist",
- "catchPhrase" => "Proactive didactic contingency",
- "bs" => "synergize scalable supply-chains"
- ]
- ],
- ];
- $posts = [
- [
- "user_id" => 1,
- "id" => 1,
- "title" => "delectus aut autem",
- "completed" => false
- ],
- [
- "user_id" => 2,
- "id" => 21,
- "title" => "suscipit repellat esse quibusdam voluptatem incidunt",
- "completed" => true
- ],
- [
- "user_id" => 2,
- "id" => 22,
- "title" => "voluptas quo tenetur perspiciatis explicabo natus",
- "completed" => false
- ]
- ];
- foreach ($users as $key => $user) {
- foreach ($posts as $post) {
- if ($user['id'] == $post['user_id']) {
- $users[$key]['posts'][] = $post;
- }
- }
- }
- ?>
- <?php foreach ($users as $user): ?>
- <div style="border: 1px solid;margin-bottom: 1em">
- <h1><?= $user['username'] ?> <?= $user['email'] ?> <?= $user['phone'] ?></h1>
- <h5>posts</h5>
- <?php foreach ($user['posts'] as $post): ?>
- <ul>
- <li style="margin-bottom: 1em;box-shadow: 1px 1px 5px;padding: 0.4em;">
- <input type="checkbox" <?= $post['completed'] ? 'checked' : '' ?>>
- <h3 class="<?= $post['completed'] ? 'completed' : '' ?>"><?= $post['title'] ?></h3>
- </li>
- </ul>
- <?php endforeach; ?>
- </div>
- <?php endforeach; ?>