Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
PHP - JSON Question
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Skythrust" data-source="post: 467717" data-attributes="member: 87030"><p>Thanks [USER=9520]@Wess[/USER]!</p><p></p><p>What is the best way to filter the JSON Array? On the internet they are talking about filter_array(), but it seems like that is not working for me. For example the Department to show only the persons which are in Dept 3, or the online state is true.</p><p></p><p>[CODE=json]$jsonstringDept = '[</p><p> {"DeptId":1,"DepartmentName":"CEO"},</p><p> {"DeptId":2,"DepartmentName":"NASDAQ"},</p><p> {"DeptId":3,"DepartmentName":"Marvel Studios"},</p><p> {"DeptId":4,"DepartmentName":"Lucasfilm"}</p><p> ]';</p><p></p><p>$jsonstringPerson = '[ </p><p> {"FrstName":"Henry","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"},</p><p> {"FrstName":"Klaus","Middlename":"","LastName":"Mikaelson","Online":true,"DeptId":"2"},</p><p> {"FrstName":"Kylo","Middlename":"","LastName":"Ren","Online":false,"DeptId":"4"},</p><p> {"FrstName":"Stan","Middlename":"","LastName":"Lee","Online":false,"DeptId":"3"},</p><p> {"FrstName":"Kevin","Middlename":"","LastName":"McNally","Online":false,"DeptId":"3"},</p><p> {"FrstName":"Katherine","Middlename":"","LastName":"Pierce","Online":false,"DeptId":"2"},</p><p> {"FrstName":"Clint","Middlename":"","LastName":"Barton","Online":true,"DeptId":"3"},</p><p> {"FrstName":"Hope","Middlename":"van","LastName":"Dyne","Online":false,"DeptId":"3"}</p><p> ]';</p><p>[/CODE]</p><p></p><p>Full Code;</p><p>[CODE=php]<?php</p><p>$i =0;</p><p>echo "<table><tr>";</p><p>foreach($data as $record)</p><p>{</p><p> if ($record['APBArea'] == 2) { $APBAreadiv = 'TextOn'; $APBCheck = 'checked'; } else { $APBAreadiv = 'TextOff'; $APBCheck = 'unchecked'; }</p><p> if ($record['Pin'] == 1) { $BHVDiv = 'fas fa-user-plus'; $BHVValue = ' (BHV)'; } else { $BHVDiv = 'fas fa-user'; $BHVValue = ''; }</p><p></p><p> $i++;</p><p> echo "<td><div class=".$APBAreadiv."><i class='".$BHVDiv."'></i>"</p><p> .' '.$record['FrstName'] .' '. $record['MiddleName'] .' '. $record['LastName']. $BHVValue;</p><p></p><p> echo '<label class="switch"></p><p> <input type="checkbox"'.$APBCheck.'></p><p> <span class="slider round"></span></p><p> </label></p><p> </div> </p><p> </td>';</p><p> $i++;</p><p> if ($i % 5 == 0) { echo '</tr><tr>'; }</p><p>} </p><p>echo '</table>'; </p><p>}</p><p></p><p>?> [/CODE]</p></blockquote><p></p>
[QUOTE="Skythrust, post: 467717, member: 87030"] Thanks [USER=9520]@Wess[/USER]! What is the best way to filter the JSON Array? On the internet they are talking about filter_array(), but it seems like that is not working for me. For example the Department to show only the persons which are in Dept 3, or the online state is true. [CODE=json]$jsonstringDept = '[ {"DeptId":1,"DepartmentName":"CEO"}, {"DeptId":2,"DepartmentName":"NASDAQ"}, {"DeptId":3,"DepartmentName":"Marvel Studios"}, {"DeptId":4,"DepartmentName":"Lucasfilm"} ]'; $jsonstringPerson = '[ {"FrstName":"Henry","Middlename":"","LastName":"Walton","Online":true,"DeptId":"4"}, {"FrstName":"Klaus","Middlename":"","LastName":"Mikaelson","Online":true,"DeptId":"2"}, {"FrstName":"Kylo","Middlename":"","LastName":"Ren","Online":false,"DeptId":"4"}, {"FrstName":"Stan","Middlename":"","LastName":"Lee","Online":false,"DeptId":"3"}, {"FrstName":"Kevin","Middlename":"","LastName":"McNally","Online":false,"DeptId":"3"}, {"FrstName":"Katherine","Middlename":"","LastName":"Pierce","Online":false,"DeptId":"2"}, {"FrstName":"Clint","Middlename":"","LastName":"Barton","Online":true,"DeptId":"3"}, {"FrstName":"Hope","Middlename":"van","LastName":"Dyne","Online":false,"DeptId":"3"} ]'; [/CODE] Full Code; [CODE=php]<?php $i =0; echo "<table><tr>"; foreach($data as $record) { if ($record['APBArea'] == 2) { $APBAreadiv = 'TextOn'; $APBCheck = 'checked'; } else { $APBAreadiv = 'TextOff'; $APBCheck = 'unchecked'; } if ($record['Pin'] == 1) { $BHVDiv = 'fas fa-user-plus'; $BHVValue = ' (BHV)'; } else { $BHVDiv = 'fas fa-user'; $BHVValue = ''; } $i++; echo "<td><div class=".$APBAreadiv."><i class='".$BHVDiv."'></i>" .' '.$record['FrstName'] .' '. $record['MiddleName'] .' '. $record['LastName']. $BHVValue; echo '<label class="switch"> <input type="checkbox"'.$APBCheck.'> <span class="slider round"></span> </label> </div> </td>'; $i++; if ($i % 5 == 0) { echo '</tr><tr>'; } } echo '</table>'; } ?> [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
PHP - JSON Question
Top