Jump to content

Recommended Posts

I have two products that I want to sort by say "Id:17, value: xxx" using php

The page will end up looking like this

 

Part Number    Diameter  Effective focal  back focal  cntr thickness      edge thickness

L-AOC000        6.00          10.00              7.52          4.75                  3.5

 

here is the decoded json for the two products ( there are a few hundred products)

 

{"id":"16","value":"L-AOC000"},{"id":"17","value":"6.00"},{"id":"18","value":"10.00"},{"id":"19","value":"7.52"},{"id":"20","value":"4.75"},{"id":"21","value":"3.50"}

 

{"id":"16","value":"L-AOC001"},{"id":"17","value":"7.00"},{"id":"18","value":"11.00"},{"id":"19","value":"8.52"},{"id":"20","value":"3.75"},{"id":"21","value":"2.50"}

 

any help would be appreciated

Link to comment
https://forums.phpfreaks.com/topic/178283-json-sort-with-php/
Share on other sites

Well I'm trying to hack this program i have (open source). A a point in a function the script returns

the values that i posted above. i want to be able to sort those values before the function strips the strings further. I am somewhat new to programming (teaching myself) but i can understand it.

here is what the function looks like

 

elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {

                    // array, or object notation

 

                    if ($str{0} == '[') {

                        $stk = array(SERVICES_JSON_IN_ARR);

                        $arr = array();

                    } else {

                        if ($this->use & SERVICES_JSON_LOOSE_TYPE) {

                            $stk = array(SERVICES_JSON_IN_OBJ);

                            $obj = array();

                        } else {

                            $stk = array(SERVICES_JSON_IN_OBJ);

                            $obj = new stdClass();

                        }

                    }

 

                    array_push($stk, array('what'  => SERVICES_JSON_SLICE,

                                          'where' => 0,

                                          'delim' => false));

 

                    $chrs = substr($str, 1, -1);

 

                    $chrs = $this->reduce_string($chrs);

 

                    if ($chrs == '') {

                        if (reset($stk) == SERVICES_JSON_IN_ARR) {

                            return $arr;

 

                        } else {

                            return $obj;

 

                        }

                    }

//print("$chrs");<-------- at this point is where I get the strings i posted above.  is it even possible to sort at this point?

 

Link to comment
https://forums.phpfreaks.com/topic/178283-json-sort-with-php/#findComment-940104
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.