Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/11/2021 in all areas

  1. Hello everyone, I'm very new to this site. I'm here to learn how to code in PHP as I once did. I'm very raw at tho, and I'm looking to start back up in it again. So again, hello everyone and remember I'm new. So any dummy questions I made ask, please bear with me. I would like to start my own web site for my own purpose. Something very small and for my needs. And to top it all off, I'm going to run it on a Raspberry Pi from my home. This is should be a fun trip. Thanks Sincerely Dan
    2 points
  2. PS If you want the ID to be the key in the categories array, use $categories = array_column($array, $column, 'id'); // get the category values with id as the key
    1 point
  3. If you are using print_r(), put it between <pre>..</pre> tags to make it legible. echo '<pre>' . print_r($array, true) . '</pre>'; Try $items[$item->id] = $item->category; Try to limit the number of posts on the same question to 1.
    1 point
  4. $json = '[{"id":"1","category":"public health","type":"top"},{"id":"2","category":"environment","type":"top"},{"id":"3","category":"global unrest","type":"top"},{"id":"4","category":"military","type":"top"},{"id":"6","category":"super powers","type":"top"},{"id":"7","category":"technology","type":"top"},{"id":"8","category":"human rights","type":"top"},{"id":"60","category":"space race","type":"top"},{"id":"67","category":"globalism","type":"top"},{"id":"87","category":"government","type":"top"}]'; $array = json_decode($json, 1); // decode as an array $column = 'category'; $categories = array_column($array, $column); // get the $column values echo '<pre>' . print_r($categories, 1) . '</pre>'; gives Array ( [0] => public health [1] => environment [2] => global unrest [3] => military [4] => super powers [5] => technology [6] => human rights [7] => space race [8] => globalism [9] => government )
    1 point
  5. Another thing is PHP OOP is great with inheritance where a lot of that code to put it nicely could be streamline and some of the methods wouldn't even have to be used. Something to look into?
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.