Pick a value from an array randomly for a particular day

dev1234

I have an array which has the id's and my code is as following,

    //Random Offer of the day
    $offers = Offer::model()->findAll();
    $randomOffer = null;
    $dataOffer = new GreenPointsActionDataObj();
    if ($offers) {
        $randomNo = mt_rand(0, count($offers) - 1);
        $randomOffer = $offers[$randomNo];
        $dataOffer->id = intval($randomOffer->id);
        $dataOffer->title = $randomOffer->name;
        $dataOffer->thumbUrl = $randomOffer->thumbUrl;
        $dataOffer->description = $randomOffer->description;
    }
    $data[] = $dataOffer;

I need this to be day based, for example it should be always one for the day and next day another random but should be same the whole day.

how can i get this done ?

This is my suggestion, when an id is taken, i should maintain it with a day stored in DB.

Kumar V

Try this code:

Method 1:

To get the unique offer for year.

$weekday = date('l', time()); // will return the weekday number
$randomOffer = $offers[$weekday];

Method 2

To get the unique offer for year.

$daycnt = date('z', time())+1;
$randomOffer = $offers[$daycnt];

Method 3

To get the unique offer for month.

$cur_date = date('d', time());
$randomOffer = $offers[$cur_date ];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pick a value from an array randomly for a particular day

From Java

How do I pick randomly from an array?

From Dev

How to randomly pick value from a list in Unity3D?

From Dev

C# randomly pick elements from one array to move to another

From Dev

randomly pick from 4 tables

From Dev

Randomly pick array values, add them up, until you get a certain value in php

From Dev

Randomly pick array values, add them up, until you get a certain value in php

From Dev

Count particular key value from array of object

From Dev

How to get a object from array for a particular value

From Dev

Randomly pick elements from a vector of counts

From Dev

Pick a number randomly from two numbers

From Dev

How to pick one key from a dictionary randomly

From Dev

Pick a number randomly from two numbers

From Dev

Android: Randomly pick images from 2 pools

From Dev

Unserscore template - how to pick a single value from the array?

From Dev

google maps - pick value from array and assign to marker

From Dev

Want to create particular property value array from array

From Dev

Randomly selecting a pushed value with an input from an array with a button in JS

From Dev

Randomly pick variables and give them one value AS3

From Dev

pick first day from many panda dataframes

From Dev

How to randomly pick an array index based on the index's "score"?

From Dev

How to remove a particular value from an array in Node.js

From Dev

How to remove a particular value from an array in Node.js

From Dev

How to assign a value array from json to particular table based on ID

From Dev

Iwant to delete particular key & value from array of object in java script

From Java

Pick a random element from an array

From Dev

Pick specific elements from array

From Dev

SASS: randomly pick background-image from a list

From Dev

How to randomly pick a string from multiple finals strings in Java?

Related Related

  1. 1

    Pick a value from an array randomly for a particular day

  2. 2

    How do I pick randomly from an array?

  3. 3

    How to randomly pick value from a list in Unity3D?

  4. 4

    C# randomly pick elements from one array to move to another

  5. 5

    randomly pick from 4 tables

  6. 6

    Randomly pick array values, add them up, until you get a certain value in php

  7. 7

    Randomly pick array values, add them up, until you get a certain value in php

  8. 8

    Count particular key value from array of object

  9. 9

    How to get a object from array for a particular value

  10. 10

    Randomly pick elements from a vector of counts

  11. 11

    Pick a number randomly from two numbers

  12. 12

    How to pick one key from a dictionary randomly

  13. 13

    Pick a number randomly from two numbers

  14. 14

    Android: Randomly pick images from 2 pools

  15. 15

    Unserscore template - how to pick a single value from the array?

  16. 16

    google maps - pick value from array and assign to marker

  17. 17

    Want to create particular property value array from array

  18. 18

    Randomly selecting a pushed value with an input from an array with a button in JS

  19. 19

    Randomly pick variables and give them one value AS3

  20. 20

    pick first day from many panda dataframes

  21. 21

    How to randomly pick an array index based on the index's "score"?

  22. 22

    How to remove a particular value from an array in Node.js

  23. 23

    How to remove a particular value from an array in Node.js

  24. 24

    How to assign a value array from json to particular table based on ID

  25. 25

    Iwant to delete particular key & value from array of object in java script

  26. 26

    Pick a random element from an array

  27. 27

    Pick specific elements from array

  28. 28

    SASS: randomly pick background-image from a list

  29. 29

    How to randomly pick a string from multiple finals strings in Java?

HotTag

Archive