samwilson /
simple-wikidata
| 1 | <?php |
||
| 2 | |||
| 3 | require_once __DIR__ . '/../vendor/autoload.php'; |
||
| 4 | |||
| 5 | // Any PSR6 cache can be used. |
||
| 6 | $cache = new Stash\Pool( new \Stash\Driver\FileSystem() ); |
||
| 7 | |||
| 8 | $sparql = 'SELECT ?item WHERE { |
||
| 9 | ?item wdt:P31 wd:Q54050 |
||
| 10 | } LIMIT 5'; |
||
| 11 | $query = new \Samwilson\SimpleWikidata\Query( $sparql, 'en', $cache ); |
||
| 12 | $hills = $query->getItems(); |
||
| 13 | foreach ( $hills as $hill ) { |
||
| 14 | $heights = $hill->getPropertyOfTypeQuantity( 'P2044' ); |
||
| 15 | if ( !$heights ) { |
||
| 16 | echo "No heights found for " . $hill->getLabel() . "\n"; |
||
| 17 | continue; |
||
| 18 | } |
||
| 19 | $height = array_shift( $heights ); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 20 | echo $hill->getLabel() . " is " |
||
| 21 | . $height['amount'] . " " . $height['unit']->getLabel() . " high.\n"; |
||
| 22 | } |
||
| 23 |