Jump to content

PageArray question


kemeris
 Share

Recommended Posts

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

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/>";

  • Like 4
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...