Jump to content

Search the Community

Showing results for tags 'arrays sorting'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hi I'm not the best at arrays and have got thecode below which is pulling values out based on posted in variables eg mountains, nightlife, I'm then adding them together per country the ratings for these for each country and them sorting the values to leave me with an array showing highest rated island at the first in the array Is there a more efficient way of doing the same thing as I have done below? Thankyou for everyones help in advance <?php //posted values in $tripw = $_POST['trip']; $entries = array(); //loop over islands and pull all ratings and category names out ?> {exp:channel:entries channel="islands"} {rating_level} <?php $island = "{url_title}"; $rate_num = array( 'catname' => "{rate_cat}{title}{/rate_cat}", 'rating' => "{rate_num}"); $entries[$island][] = $rate_num; ?> {/rating_level} {/exp:channel:entries} <?php //loop over values and pull out ones which match the posted categories and add together to give each islands a total $total = ""; foreach ($entries as $key => $val) { foreach($val as $subarray) { //pull in posted categories foreach($tripw as $tt2){ if($subarray['catname'] == $tt2) { $total += $subarray['rating']; } } } $topr[] = array('island' => $key,'total'=> $total); $total = 0; } //sort array highest to lowest based on total of each island function subval_sort( $a, $subkey, $order='dec' ) { foreach( $a as $k=>$v ) $b[$k] = strtolower( $v[$subkey] ); if( $order === 'dec' ) arsort( $b ); else asort( $b ); foreach( $b as $key=>$val ) $c[$key] = $a[$key]; return $c; } $topr = subval_sort($topr,'total');
×
×
  • 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.