Created
March 28, 2022 10:42
-
-
Save michaelbragg/5e046b8966dc5f7c5a6daf332adac2fa to your computer and use it in GitHub Desktop.
Example of returning a Class object over an array in PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Appeals: List All Appeals. | |
* | |
* <code> | |
* class(AllAppeals) { | |
* "data" => class(Appeals) { | |
* "christmas_appeal_2022" => class(Appeal) { | |
* "name" => :string "Christmas Appeal 2022", | |
* "slug" => :string "christmas-appeal-2022", | |
* "salesforce_id" => :string "1234567890ABC", | |
* }, | |
* "cyber_monday_appeal_2022" => class(Appeal) { | |
* "name" => :string "Cyber Monday Appeal 2022", | |
* "slug" => :string "cyber-monday-appeal-2022", | |
* "salesforce_id" => :string "1234567890DEF", | |
* }, | |
* }, | |
* "updated_at" => :string "2022-02-22 15:16:17", | |
* } | |
* </code> | |
* | |
* @author Michael Bragg <https://www.michaelbragg.com> | |
*/ | |
use Vatu\WordPress\Plugin\Example\Appeals; | |
$data = Appeals::all_appeals(); | |
// Output specific appeal attribute. | |
echo $data->data->christmas_appeal_2021->salesforce_id; | |
// Returns: 1234567890ABC | |
// Loop through all appeals. | |
foreach ($data->data as $key => $value) { | |
echo "{$value->name}: {$value->slug}<br/>"; | |
} | |
// Returns: | |
// Christmas Appeal 2022: christmas-appeal-2022 | |
// Cyber Monday Appeal 2022: cyber-monday-appeal-2022 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment