Get random values from array on PHP using foreach and array_slice? -
How can I randomize results on this code?
I have an array with more than four objects on it, but I would like to get only four out of them but not in order, how do I feel like doing this? It can be done using $ code as My array foreach (array_slice ??
$ i = 0; foreach (array_slice ($ items_array, 0,4) {$ Output. = 'Item ID:'. $ Item ['id']; $ i ++;}
one: 6: {i: 0; a: 4: {s: 5: of "title" of: 17: "SPEDITION" of: 2: of "id": 11: "ZCXbgH1JDt4" : 3: of "uRL": 40: "Embed / ZCXbgH1JDt4" of: 5: "image" of: 38: "transport";} I: 1; one: 4: {s: 5: "title" of: 77 : "DC ......
$ output = array_rand ( $ Items_array, 4);
Comments
Post a Comment