Haris
Haris

Reputation: 545

Optimizing rating array

I have a rating system on my Wordpress that came with the theme. The maximum rating possible is 10, so I wanted to edit this and make a 100 possible rating. So I edited this part:

public static function max_rating( $listing_id = null ) {
    $default = 100;

So now it understands that the max possible rating is 100. But under the rating array, there were these lines:

    $rating_options = array(
        '1' => 1,
        '2' => 2,
        '3' => 3,
        '4' => 4,
        '5' => 5,
        '6' => 6,
        '7' => 7,
        '8' => 8,
        '9' => 9,
        '10' => 10,

Which understand that the maximum possible rating is 10. Now I want to make a maximum rating of 100, but adding '11' => 11, '12' => 12, '13' => 13 etc takes a lot of time and it consumes a lot of space in my file. Is there a possiblity to shorten this or do I really have to enter every rating up to 100?

Upvotes: 2

Views: 88

Answers (2)

Ron van der Heijden
Ron van der Heijden

Reputation: 15080

The accepted answer points you in the right direction.

Additional I would advice using array_combine like so:

$range = range(1,100);
$rating_options = array_combine($range, $range);
// array(1=>1, 2=>2, ...)

This way, your keys will be the same as the values.

Upvotes: 2

treyBake
treyBake

Reputation: 6568

you can use PHP's range function:

$ratings = range(0, 100);

reference: https://secure.php.net/manual/en/function.range.php

Upvotes: 1

Related Questions