[Developers] Dealing With Arrays: PHP + MQL

Will Merydith will.merydith at gmail.com
Tue Dec 16 18:12:57 UTC 2008


I'm developing a Freebase module for the Drupal community and am stuck on
how to handle arrays.  I'm a long time Java programmer new to PHP (and
Drupal).

For example:

----
$metaweb = new Metaweb();
$mql = array("type" => "/film/film", "id" => "/en/king_kong_1976",  "name"
=> null, "starring" => array());
$result = $metaweb->read($mql);

$name = $result["name"]
$id = $result["id"];
---

It's easy enough to pull out the name and id.  But I need the actor and
character data from the starring array as well.

I've tried the syntax below but that doesn't work.  I'm having difficulty
understanding how to translate the starring array to a JSON query.  Any help
appreciated.

----
$metaweb = new Metaweb();
$mql = array("type" => "/film/film", "id" => "/en/king_kong_1976",  "name"
=> null, "starring" => array("actor" => null, "character" => null));
$result = $metaweb->read($mql);

$name = $result["name"]
$id = $result["id"];
$stars = $result["starring"];
foreach ($stars as $star) {
  $star_actor_name = $star->actor;
  $star_character = $star->character;
}
---


-- 
will at 3mix.com

cell 641.233.7548

CEO - http://3mix.com
http://linkedin.com/in/merydith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freebase.com/pipermail/developers/attachments/20081216/764c3397/attachment.htm 


More information about the Developers mailing list