I have an object with 3 properties. I'd like to input a number 1,2, or 3 (0,1,or 2 is fine too) and sort the object in ascending numerical order based on one its property values.
Here's what my object looks like:
var_dump($obj);
array(3) {
[0]=> object(stdClass)#25 (92) {
["file_id"]=> string(1) "6"
["name"]=> string(1) "1st item"
}
[1]=> object(stdClass)#26 (92) {
["file_id"]=> string(1) "7"
["name"]=> "2nd item"
}
[2]=> object(stdClass)#27 (92) {
["file_id"]=> string(1) "8"
["name"]=> "3rd item"
}
}
If I input 1, then the output would look like this:
file_id name
6 1st item
7 2nd item
8 3rd item
If I input 2, then the output would be:
7 2nd item
8 3rd item
6 1st item
If I input 3, then the output would be:
8 3rd item
6 1st item
7 2nd item
This question is nearly identical to one I asked earlier on Stackoverflow , the sole exception being that I need to sort() on the index positions of the file_id values and not on the file_id values themselves. I.e., I need to sort on 1,2,3 and not 6,7,8.
If you are particularly excited about this question (yes I realize this is unlikely), i'd be curious to know what the numbers 25 and 92 stand for in the output: object(stdClass)#25 (92).
var_dumpor aprint_rto display the object info?var_dump(). Is converting$objto an array needed for indexing? I'm using Codeigniterquery->result()which returns "an array of objects".var_dump(), I think the#25is the resource ID of the object;92may be the size of the object in bytes.class A { protected $p1; }-> (1),class B { protected $p1; protected $p2; }-> (2) and so on. This also applies to properties that are added only at runtime (i.e. outside the class contract).