Traversing an nested array and transform some values - php

I'm looking for a clean solution to transform a nested array.
Here is what I'm trying to achieve...
Original array:
$map = array(
'name' => 'super test',
'machine_name' => 'super_test',
'class' => 'openlayers_map_map',
'options' => array(
'width' => 'auto',
'height' => '300px',
'contextualLinks' => 1,
'provideBlock' => 1,
'view' => array(
'center' => array(
'lat' => '0',
'lon' => '0',
),
'rotation' => '0',
'zoom' => '2',
),
'layers' => array(
'0' => array(
'name' => 'Ma super layer',
'machine_name' => 'plouf',
'class' => 'openlayers_layer_tile',
'options' => array(
'source' => array(
'name' => 'Ma super layer',
'machine_name' => 'plouf',
'class' => 'openlayers_source_osm'
),
'param1' => 'ca roule'
)
),
),
'controls' => array(
'control_mouseposition',
'0' => array(
'name' => 'Control attribution',
'machine_name' => 'openlayers_control_attribution',
'class' => 'openlayers_control_attribution',
'options' => array(
'collapsible' => 1
)
),
'control_rotate',
'control_zoom',
),
'interactions' => array(
'interaction_doubleclickzoom',
'interaction_dragpan',
'interaction_dragrotateandzoom',
'interaction_mousewheelzoom',
),
)
);
Final array:
$map = array(
'name' => 'super test',
'machine_name' => 'super_test',
'class' => 'openlayers_map_map',
'options' => array(
'width' => 'auto',
'height' => '300px',
'contextualLinks' => 1,
'provideBlock' => 1,
'view' => array(
'center' => array(
'lat' => '0',
'lon' => '0',
),
'rotation' => '0',
'zoom' => '2',
),
'layers' => array(
'0' => (object) openlayers_layer_tile
'name' => 'Ma super layer',
'machine_name' => 'plouf',
'class' => 'openlayers_layer_tile',
'options' => array(
'source' => (object) openlayers_source_osm
'name' => 'Ma super layer',
'machine_name' => 'plouf',
'class' => 'openlayers_source_osm'
),
'param1' => 'ca roule'
)
),
),
'controls' => array(
'control_mouseposition',
'0' => (object) openlayers_control_attribution
'name' => 'Control attribution',
'machine_name' => 'openlayers_control_attribution',
'class' => 'openlayers_control_attribution',
'options' => array(
'collapsible' => 1
)
),
'control_rotate',
'control_zoom',
),
'interactions' => array(
'interaction_doubleclickzoom',
'interaction_dragpan',
'interaction_dragrotateandzoom',
'interaction_mousewheelzoom',
),
)
);
Basically, I need to traverse the array, find all children with the 'class' key and transform them into objects of the same name.

If you don't have the classes ready to be instantiated, this code will create anonymous objects instead. (The class name still being present as a property.)
function class_to_object (&$arr) {
if (is_array($arr)) {
foreach ($arr as $key => &$val) {
class_to_object($val);
}
if (isset($arr['class'])) {
$arr = (object) $arr;
}
}
}
class_to_object($map);
Result :
(Notice that the first array is turned into an object, since it contains the field "class" too. I guess you can tweak the function easily enough if you don't want that behavior)
stdClass Object
(
[name] => super test
[machine_name] => super_test
[class] => openlayers_map_map
[options] => Array
(
[width] => auto
[height] => 300px
[contextualLinks] => 1
[provideBlock] => 1
[view] => Array
(
[center] => Array
(
[lat] => 0
[lon] => 0
)
[rotation] => 0
[zoom] => 2
)
[layers] => Array
(
[0] => stdClass Object
(
[name] => Ma super layer
[machine_name] => plouf
[class] => openlayers_layer_tile
[options] => Array
(
[source] => stdClass Object
(
[name] => Ma super layer
[machine_name] => plouf
[class] => openlayers_source_osm
)
[param1] => ca roule
)
)
)
[controls] => Array
(
[0] => stdClass Object
(
[name] => Control attribution
[machine_name] => openlayers_control_attribution
[class] => openlayers_control_attribution
[options] => Array
(
[collapsible] => 1
)
)
[1] => control_rotate
[2] => control_zoom
)
[interactions] => Array
(
[0] => interaction_doubleclickzoom
[1] => interaction_dragpan
[2] => interaction_dragrotateandzoom
[3] => interaction_mousewheelzoom
)
)
)

This totally untested recursive function may get you on the right track:
function recursive_hydrate_array($arr)
{
if(!is_array($arr) || !isset($arr["class"]))
{
throw new Exception("Argument is not an array or does not have a 'class' key.");
}
$klass = $arr["class"];
unset($arr["class"]);
$obj = new $klass();
foreach($arr as $k => $v)
{
if(is_array($arr[$k]) && isset($arr[$k]["class"]))
{
$obj->{$k} = recursive_hydrate_array($arr[$k]);
}
else
{
$obj->{$k} = $arr[$k];
}
}
return $obj;
}
Note that I am making three assumptions here:
The classes in question already exist.
Each class can be instantiated without passing any parameters to its constructor.
All relevant properties of each class are public and can be set from outside of the class.

Related

Referencing field from stdClass Object which contains an array of drawable information

I'd like to return the value of the Birthday field from the following massive mixed array of data containing nested arrays and stdClass Objects. I tried the following code but it didn't work, I would be extremely grateful for any help.
$data->_field_data['nid']['entity']->field_player_birthday['und'][0]['value'];
PHP:
stdClass::__set_state(array(
'node_field_data_field_game_players_nid' => '2931',
'node_title' => '1539634465',
'nid' => '8114',
'node_language' => 'tr',
'field_data_field_player_birthday_node_entity_type' => 'node',
'_field_data' => array (
'node_field_data_field_game_players_nid' => array (
'entity_type' => 'node',
'entity' => stdClass::__set_state(
array( 'vid' => '2931',
'uid' => '1',
'title' => 'Fernando Muslera',
'log' => '',
'status' => '1',
'comment' => '1',
'promote' => '0',
'sticky' => '0',
'ds_switch' => '',
'nid' => '2931',
'type' => 'player',
'language' => 'und',
'created' => '1520727843',
'changed' => '1539137801',
'tnid' => '0',
'translate' => '0',
'revision_timestamp' => '1539137801',
'revision_uid' => '1',
'body' =>
array ( ), 'field_player_address' => array ( 'und' => array ( 0 =>
array ( 'country' => 'AR', 'administrative_area' => 'B',
'sub_administrative_area' => NULL, 'locality' => 'Buenos Aires',
'dependent_locality' => '', 'postal_code' => '', 'thoroughfare' => '',
'premise' => '', 'sub_premise' => NULL, 'organisation_name' => NULL,
'name_line' => NULL, 'first_name' => NULL, 'last_name' => NULL, 'data'
=> NULL, ), ), ), 'field_geofield' => array ( 'und' => array ( 0 => array ( 'geom' => 'POINT (-58.3815591 -34.6036844)', 'geo_type' =>
'point', 'lat' => '-34.603684400000', 'lon' => '-58.381559100000',
'left' => '-58.381559100000', 'top' => '-34.603684400000', 'right' =>
'-58.381559100000', 'bottom' => '-34.603684400000', 'geohash' =>
'69y7pkxfgjdq4', ), ), ), 'field_player_search_news' => array ( ),
'field_player_map' => array ( ), 'field_player_birthday' => array (
'und' => array ( 0 => array ( 'value' => '1986-06-16 00:00:00',
'timezone' => 'America/New_York', 'timezone_db' => 'America/New_York',
'date_type' => 'datetime', ), ), ), 'field_player_team' => array (
'und' => array ( 0 => array ( 'tid' => '328', ), ), ), 'field_image'
=> array ( ), 'field_game_rating' => array ( 'und' => array ( 0 => array ( 'rating' => '90', 'target' => NULL, ), ), ), 'rdf_mapping' =>
array ( 'rdftype' => array ( 0 => 'sioc:Item', 1 => 'foaf:Document',
), 'title' => array ( 'predicates' => array ( 0 => 'dc:title', ), ),
'created' => array ( 'predicates' => array ( 0 => 'dc:date', 1 =>
'dc:created', ), 'datatype' => 'xsd:dateTime', 'callback' =>
'date_iso8601', ), 'changed' => array ( 'predicates' => array ( 0 =>
'dc:modified', ), 'datatype' => 'xsd:dateTime', 'callback' =>
'date_iso8601', ), 'body' => array ( 'predicates' => array ( 0 =>
'content:encoded', ), ), 'uid' => array ( 'predicates' => array ( 0 =>
'sioc:has_creator', ), 'type' => 'rel', ), 'name' => array (
'predicates' => array ( 0 => 'foaf:name', ), ), 'comment_count' =>
array ( 'predicates' => array ( 0 => 'sioc:num_replies', ), 'datatype'
=> 'xsd:integer', ), 'last_activity' => array ( 'predicates' => array ( 0 => 'sioc:last_activity_date', ), 'datatype' => 'xsd:dateTime',
'callback' => 'date_iso8601', ), ), 'path' => array ( 'pathauto' =>
'1', ), 'cid' => '0', 'last_comment_timestamp' => '1520727843',
'last_comment_name' => NULL, 'last_comment_uid' => '1',
'comment_count' => '0', 'name' => 'efet', 'picture' => '0', 'data' =>
'a:7:{s:7:"contact";i:1;s:5:"block";a:1:{s:6:"system";a:1:{s:4:"main";i:1;}}s:16:"ckeditor_default";s:1:"t";s:20:"ckeditor_show_toggle";s:1:"t";s:14:"ckeditor_width";s:4:"100%";s:13:"ckeditor_lang";s:2:"en";s:18:"ckeditor_auto_lang";s:1:"t";}',
)), ), ), 'field_field_player_birthday' => array ( 0 => array (
'rendered' => array ( '#markup' => '1986', '#access' => true, ), 'raw'
=> array ( 'value' => '1986-06-16 00:00:00', 'timezone' => America/New_York', 'timezone_db' => 'America/New_York', 'date_type'
> => 'datetime', ), ), ), ))
You are close (as I've had to change the objects slightly to test, I hope this works)...
echo $data->_field_data['node_field_data_field_game_players_nid']['entity']
->field_player_birthday['und'][0]['value'];
Basically instead of nid, it's node_field_data_field_game_players_nid.

How to sort an array by group of field value array in PHP

I want to sort collection of data by specific values like in sql ORDER BY VALUES() but in PHP. I have array like this
$array = array(
array('name' => 'Milk', 'type' => 'drink'),
array('name' => 'Coffee', 'type' => 'drink'),
array('name' => 'Orange', 'type' => 'fruit'),
array('name' => 'Computer', 'type' => 'other'),
array('name' => 'Water', 'type' => 'other'),
);
I want order data by type but not alphabetically, instead by specific values that I specify, order by type other, following by drink, following by fruit. So the result should be:
$array = array(
array('name' => 'Computer', 'type' => 'other'),
array('name' => 'Water', 'type' => 'other'),
array('name' => 'Milk', 'type' => 'drink'),
array('name' => 'Coffee', 'type' => 'drink'),
array('name' => 'Orange', 'type' => 'fruit'),
);
I tried usort but I have no idea how to compare with 2 values to achieve that. Thanks.
You can try this way also,
$array = array(
array('name' => 'Milk', 'type' => 'drink'),
array('name' => 'Coffee', 'type' => 'drink'),
array('name' => 'Orange', 'type' => 'fruit'),
array('name' => 'Computer', 'type' => 'other'),
array('name' => 'Water', 'type' => 'other'),
);
// array_flip turns 0 => 'other', 1 => 'drink', ... into 'other' => 0, 'drink' => 1, ...
$order=array_flip(array('other','drink','fruit'));
usort($array, function($x, $y) use($order) {
if (!isset($order[$x['type']], $order[$y['type']])) {
// none of the ids have order, so sort by bare type
return $x['type'] - $y['type'];
}
else if (!isset($order[$x['type']])) {
// x does not have order, put it last
return 1;
}
else if (!isset($order[$y['type']])) {
// y does not have order, put it last
return -1;
}
// both have types, use them
return $order[$x['type']] - $order[$y['type']];
});
echo "<pre>";
print_r($array);
output:-
Array
(
[0] => Array
(
[name] => Computer
[type] => other
)
[1] => Array
(
[name] => Water
[type] => other
)
[2] => Array
(
[name] => Milk
[type] => drink
)
[3] => Array
(
[name] => Coffee
[type] => drink
)
[4] => Array
(
[name] => Orange
[type] => fruit
)
)
Yes, you can use usort like:
$array = array(
array('name' => 'Milk', 'type' => 'drink'),
array('name' => 'Coffee', 'type' => 'drink'),
array('name' => 'Orange', 'type' => 'fruit'),
array('name' => 'Computer', 'type' => 'other'),
array('name' => 'Water', 'type' => 'other'),
);
usort($array,function($a,$b){
//Define the order
$order = array( 'other' => 0 , 'drink' => 1, 'fruit' => 2 );
//Compare the order
return $order[ $a[ 'type' ] ] > $order[ $b[ 'type' ] ];
});
echo "<pre>";
print_r( $array );
echo "</pre>";
This will result to:
Array
(
[0] => Array
(
[name] => Computer
[type] => other
)
[1] => Array
(
[name] => Water
[type] => other
)
[2] => Array
(
[name] => Milk
[type] => drink
)
[3] => Array
(
[name] => Coffee
[type] => drink
)
[4] => Array
(
[name] => Orange
[type] => fruit
)
)
If in case some of the types are on the array, you can do this to make sure that the undefined will be put on the last.
usort($array,function($a,$b){
$order = array( 'other' => 0 , 'drink' => 1, 'fruit' => 2 );
$aOrder = isset( $order[ $a[ 'type' ] ] ) ? $order[ $a[ 'type' ] ] : 1000000000000;
$bOrder = isset( $order[ $b[ 'type' ] ] ) ? $order[ $b[ 'type' ] ] : 1000000000000;
return $aOrder > $bOrder;
});

Mongodb Search from Collection

I need to Search collection in mongodb having
'food_name' => 'fish'
and
'room_features' =>
array (
0 => 'Shower',
1 => 'Hairdryer',
),
I tried the following code. But the result is not-correct. I think multiple $eq is not allowed (same index in array).
array (
'$and' =>
array (
array (
'food' =>
array (
'$elemMatch' =>
array (
'food_name' =>
array (
'$eq' => 'fish',
),
),
),
),
array (
'room' =>
array (
'$elemMatch' =>
array (
'room_features' =>
array (
'$elemMatch' =>
array (
'$eq' => 'Shower'
'$eq' => 'Hairdryer'
),
),
'roomrate' =>
array (
'$eq' => new MongoInt32(2500),
),
),
),
),
),
)
Here is the document I need to search.
array (
'_id' => new MongoId("59670aca7fafd8342e3c9869"),
'subcat_name' => 'Test',
'place' => '',
'description' => '',
'created_date' => '1499970060',
'created_by' => 'Admin',
'openingtime' => '',
'closingtime' => '',
'hotel_class_id' => '594245f67fafd87e243c986a',
'hotel_type_id' => '594244177fafd884563c9869',
'latitude' => '0',
'longitude' => '0',
'dist_id' => '5911966a7fafd8c83c3c986a',
'cat_id' => '58fb230e7fafd883183c986d',
'featured' => '0',
'visited' => new MongoInt64(5),
'subcat_slug' => 'test-trivandrum-1',
'image' => NULL,
'food' =>
array (
0 =>
array (
'food_id' => '149992634012642164',
'region_id' => '5944ba947fafd883333c9869',
'food_name' => 'fish',
'type' => 'veg',
'rate' => '100',
),
1 =>
array (
'food_id' => '14999366891994980639',
'region_id' => '595c75c17fafd835173c986c',
'food_name' => 'curry',
'type' => 'veg',
'rate' => '1000',
),
),
'room' =>
array (
0 =>
array (
'room_id' => '14999346791721342880',
'roomtype' => 'DELUXE KING ROOM1',
'roomrate' => new MongoInt64(2500),
'image' => 'beach_icon33.png',
'room_features' =>
array (
0 => 'Shower',
1 => 'Hairdryer',
),
),
1 =>
array (
'room_id' => '14999346901389554873',
'roomtype' => 'DELUXE KING ROOM new',
'roomrate' => new MongoInt64(4000),
'image' => 'beach_icon34.png',
'room_features' =>
array (
0 => 'Shower',
1 => 'Bathrobe',
),
),
),
)
Please Give me an alternate way to search multiple item from array.
Thanks in advance.
I think if you want to query list you can add the list in query,
try this
{
"food" : {
"$elemMatch": {
"food_name" : "fish"
}
},
"room" : {
"$elemMatch": {
"room_features" : ["Shower", "Hairdryer"]
}
},
}
Hope this help.

PHP merge associative arrays by replacing same keys and adding new

I have an array of variable size structured like this (categories is only one of the keys inside data):
print_r($json[123]["data"]["categories"]);
array(
array(
'id' => '2',
'description' => 'Single-player'
),
array(
'id' => '1',
'description' => 'Multi-player'
),
array(
'id' => '9',
'description' => 'Co-op'
),
array(
'id' => '22',
'description' => 'Steam Achievements'
),
array(
'id' => '28',
'description' => 'Full controller support'
)
)
print_r($json[456]["data"]["categories"]);
array(
array(
'id' => '21',
'description' => 'Downloadable Content'
),
array(
'id' => '1',
'description' => 'Multi-player'
)
)
Now, I want to merge these sub-arrays (they can be in variable number) and have all keys added and replaced. I've tried array_merge but it replaces the keys without adding new ones.
In this case I need to obtain this array:
print_r($merged["data"]["categories"]);
array(
array(
'id' => '2',
'description' => 'Single-player'
),
array(
'id' => '1',
'description' => 'Multi-player'
),
array(
'id' => '9',
'description' => 'Co-op'
),
array(
'id' => '22',
'description' => 'Steam Achievements'
),
array(
'id' => '28',
'description' => 'Full controller support'
),
array(
'id' => '21',
'description' => 'Downloadable Content'
)
)
Any help?
Edit:
I think I didn't expressed myself well enough. $json[$id]["data"] has multiple keys I want to merge (categories is just an example). Also the number of $json[$id] keys is variable
Edit2:
The arrays can have duplicate values, and the depth of the keys can be variable. I need to get something like array_merge_recursive() but with same values replaced.
Edit3:
This is the current array. http://pastebin.com/7x7KaAVM I need to merge all keys that have sub-arrays
Try below code:
$json = array(
'123' => array('data' => array('categories' => array(
array(
'id' => '2',
'description' => 'Single-player'
),
array(
'id' => '1',
'description' => 'Multi-player'
),
array(
'id' => '9',
'description' => 'Co-op'
),
array(
'id' => '22',
'description' => 'Steam Achievements'
),
array(
'id' => '28',
'description' => 'Full controller support'
)
))
),
'456' => array('data' => array('categories' => array(
array(
'id' => '21',
'description' => 'Downloadable Content'
)
))
),
);
//print_r($json);
$merged = array();
foreach($json as $j1)
{
foreach($j1 as $j2)
{
foreach($j2 as $key => $j3)
{
foreach($j3 as $j4)
{
$merged[$key][] = $j4;
}
}
}
}
print_r($merged);
Result:
Array
(
[categories] => Array
(
[0] => Array
(
[id] => 2
[description] => Single-player
)
[1] => Array
(
[id] => 1
[description] => Multi-player
)
[2] => Array
(
[id] => 9
[description] => Co-op
)
[3] => Array
(
[id] => 22
[description] => Steam Achievements
)
[4] => Array
(
[id] => 28
[description] => Full controller support
)
[5] => Array
(
[id] => 21
[description] => Downloadable Content
)
)
)
Demo:
http://3v4l.org/X61bE#v430
Try this . To generalize I have added some more arrays.
<?php
$merged_array = array();
$final_array = array();
$json[123]["data"]["categories"] = array(
array(
'id' => '2',
'description' => 'Single-player'
),
array(
'id' => '1',
'description' => 'Multi-player'
),
array(
'id' => '9',
'description' => 'Co-op'
),
array(
'id' => '22',
'description' => 'Steam Achievements'
),
array(
'id' => '28',
'description' => 'Full controller support'
)
);
$json[456]["data"]["categories"] = array(
array(
'id' => '21',
'description' => 'Downloadable Content'
)
);
$json[786]["data"]["categories"] = array(
array(
'id' => '31',
'description' => 'Downloadable Content'
)
);
$json[058]["data"]["categories"] = array(
array(
'id' => '41',
'description' => 'Downloadable Content'
)
);
foreach($json as $key=>$value){
array_push($merged_array,$json[$key]["data"]["categories"]);
}
foreach($merged_array as $value){
foreach($value as $val){
array_push($final_array,$val);
}
}
print_r($final_array);
?>
RESULT
Array
(
[0] => Array
(
[id] => 2
[description] => Single-player
)
[1] => Array
(
[id] => 1
[description] => Multi-player
)
[2] => Array
(
[id] => 9
[description] => Co-op
)
[3] => Array
(
[id] => 22
[description] => Steam Achievements
)
[4] => Array
(
[id] => 28
[description] => Full controller support
)
[5] => Array
(
[id] => 21
[description] => Downloadable Content
)
[6] => Array
(
[id] => 31
[description] => Downloadable Content
)
[7] => Array
(
[id] => 41
[description] => Downloadable Content
)
)

Removing unnecessary nested index in array (generated by Cake PHP)

The following question can either be solved by probably changing my use of the find method in Cake PHP OR using some PHP function. I would prefer to solve it using Cake but it doesn't matter too much. I have any array like this:
Array
(
[0] => Array
(
[Model] => Array
(
[id] => 14
[foo] => bar
)
)
[1] => Array
(
[Model] => Array
(
[id] => 15
[foo] => something
)
) .............
I just want to remove the Model index and just use the numeric one. The following function generated this array:
$arr = $this->Model->find('all', array('contain' => false ) );
I probably need to change the 'contain' part of the call. Basically, in addition to the data that appears under each Model index, I also have a second and third model and the contain = false just restricts Cake from getting data from the current model (Model).
If I understand your question correctly, I think CakePHP's Set::combine function will help http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::combine :
$result = Set::combine($your_array, '{n}.Model.id', '{n}.Model.data');
This will result in:
Array
(
[14] => Array
(
[foo] => bar
)
[15] => Array
(
[foo] => something
)
)
you have to write your own piece of code to modify your array , here is a function that will do what you want (you can improve it)
function reformArray($array,$modelName)
{
foreach($arr as $key => $value)
{
$newArr[] = $arr[$key][$modelName];
}
return $newArr;
}
you have to pass your array and the Model Name to this function and will return you the result
$a = array(
array(
'User' => array(
'id' => 2,
'group_id' => 1,
'Data' => array(
'user' => 'mariano.iglesias',
'name' => 'Mariano Iglesias'
)
)
),
array(
'User' => array(
'id' => 14,
'group_id' => 2,
'Data' => array(
'user' => 'phpnut',
'name' => 'Larry E. Masters'
)
)
),
array(
'User' => array(
'id' => 25,
'group_id' => 1,
'Data' => array(
'user' => 'gwoo',
'name' => 'The Gwoo'
)
)
)
);
RUN THIS TO REMOVE THE MODEL NAME USER
Set::extract($a, '{n}.User');
WILL RETURN THIS
$a = array(
array(
'id' => 2,
'group_id' => 1,
'Data' => array(
'user' => 'mariano.iglesias',
'name' => 'Mariano Iglesias'
)
),
array(
'id' => 14,
'group_id' => 2,
'Data' => array(
'user' => 'phpnut',
'name' => 'Larry E. Masters'
)
),
array(
'id' => 25,
'group_id' => 1,
'Data' => array(
'user' => 'gwoo',
'name' => 'The Gwoo'
)
)
);
In CakePHP 2:
$data = $this->Model->find('all');
$data = Set::extract('/Model/.', $data );
You can achieve this result by foreach also
foreach ($data as $k => &$t) {
$t = $t['Model']
}
It will be much easier with Object. Change the Array with Object.
Actually I had faced the same problem with nested array And I found the solution with Set::map($array);
If you don't want the model_name as nested array, You can prefer this solution.
$data = array(
array(
"IndexedPage" => array(
"id" => 1,
"url" => 'http://blah.com/',
'hash' => '68a9f053b19526d08e36c6a9ad150737933816a5',
'get_vars' => '',
'redirect' => '',
'created' => "1195055503",
'updated' => "1195055503",
)
),
array(
"IndexedPage" => array(
"id" => 2,
"url" => 'http://blah.com/',
'hash' => '68a9f053b19526d08e36c6a9ad150737933816a5',
'get_vars' => '',
'redirect' => '',
'created' => "1195055503",
'updated' => "1195055503",
),
)
);
$mapped = Set::map($data);
/* $mapped now looks like: */
Array
(
[0] => stdClass Object
(
[_name_] => IndexedPage
[id] => 1
[url] => http://blah.com/
[hash] => 68a9f053b19526d08e36c6a9ad150737933816a5
[get_vars] =>
[redirect] =>
[created] => 1195055503
[updated] => 1195055503
)
[1] => stdClass Object
(
[_name_] => IndexedPage
[id] => 2
[url] => http://blah.com/
[hash] => 68a9f053b19526d08e36c6a9ad150737933816a5
[get_vars] =>
[redirect] =>
[created] => 1195055503
[updated] => 1195055503
)
)
you may do this :
$tmp = $this->Model->find('all', array('contain' => false ) );
$arr = $tmp['ModelName'];

Categories