kemeris Posted March 7, 2016 Share Posted March 7, 2016 Hi all, I have php array $return with following content. Can I pass it to PageArray and use API function like sorting Array ( [success] => 1 [products] => Array ( [1] => Array ( [id] => 1 [type] => 5 [name] => Product1 ) [2] => Array ( [id] => 2 [type] => 5 [name] => Product2 ) ) ) Thanks Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 7, 2016 Share Posted March 7, 2016 You could use WireArray's functionality, but it's not as easy as simply passing in an array. You'd need at least a class extending WireData, which holds those productsData. Link to comment Share on other sites More sharing options...
Soma Posted March 7, 2016 Share Posted March 7, 2016 This could look like this in a template $arrayData = array( "success" => 1, "products" => Array( Array( "id" => 1, "type" => 6, "name" => "product1", "title" => "Product1", ), Array( "id" => 2, "type" => 5, "name" => "product2", "title" => "Product2", ) ) ); class MyData extends WireData {} $someData = new WireArray(); foreach($arrayData['products'] as $prod){ $p = new MyData(); foreach($prod as $key => $val) $p->$key = $val; $someData->add($p); } $someData->sort("-type"); foreach($someData as $r) echo "$r->title<br/>"; $result = $someData->find("title=Product1"); foreach($result as $r) echo "$r->title<br/>"; 4 Link to comment Share on other sites More sharing options...
kemeris Posted March 7, 2016 Author Share Posted March 7, 2016 Thanks for your very detailed answer! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now