Get True 50/50 Value For Split-Testing Users In PHP

So, one of the projects I’m working on is a sales funnel & at a particular point in the process, I’m trying to figure out whether a video or written text works best with regards to converting users.

Obviously, I need to do a split test… But how can I get a get true 50/50 value in PHP?

Initially the 2 answers the sprung to mind were to use a simple function this & hope for the best:


mt_rand(0,1);

Or to store values in the database & check them for each user to determine what to display.

However, neither solution is ideal.

And then the simple solution sprung into my head (it’s always the last thing to pop into my mind, lol).

The simple solution is to just run an even/odd check on the user ID, like so:


if (($user_id % 2) == 0) {

// user id is even - show video

} else {

// user id is odd - show text

}

Easy 🙂

Leave a Comment