Create partial ranges of an int array in PHP - php

Let's say I have an array like this :
$intarray = array("300","350","399","650","625","738","983","1200","1050");
how can I display this array to user like this :
Price
_________________
[] 300 - 699 (5)
[] 700 - 999 (2)
[] 1000 - 1500 (2)
Details :
as in the example I wanted to show the user not the whole elements but option to select between them by giving limits low and max limits. So if user select 300 - 699, page display the results between 300-699
That $intarray is generated dynamically so some code must handle the splitting. Array can
have more elements. What I want is divide the numbers like 5 range options to show the user.

Having in mind my comment, I assume you want to count particular ranges.
<?php
$intarray = array("300","350","399","650","625","738","983","1200","1050");
//echo "[] ". $intarray[0]. " - " .$intarray[4][0]."99"; # that was in my comment
$ranges = array(
0 => array(
'min' => 300,
'max' => 699
),
1 => array(
'min' => 700,
'max' => 999
),
2 => array(
'min' => 1000,
'max' => 1500
)
);
foreach ($intarray as $val) {
for ($i = 0; $i < count($ranges); $i++){
if ($val >= $ranges[$i]['min'] && $val <= $ranges[$i]['max']) {
$range_values[$i][] = $val;
}
}
}
var_dump($range_values);
array (size=3)
0 =>
array (size=5)
0 => string '300' (length=3)
1 => string '350' (length=3)
2 => string '399' (length=3)
3 => string '650' (length=3)
4 => string '625' (length=3)
1 =>
array (size=2)
0 => string '738' (length=3)
1 => string '983' (length=3)
2 =>
array (size=2)
0 => string '1200' (length=4)
1 => string '1050' (length=4)
You can use count() in order to display the thing in the brackets
for ($i = 0; $i < count($ranges); $i++) {
$max = max($range_values[$i]);
echo "[] " . min($range_values[$i]) . " - " . $max[0]."99" . " (". count($range_values[$i]).")" . "<br />";
}
[] 300 - 699 (5)
[] 738 - 999 (2)
[] 1050 - 199 (2)
Or just display the ranges (as it was the desired output?) and count($ranges_values) current iteration
for ($i = 0; $i < count($ranges); $i++) {
echo "[] " . $ranges[$i]['min'] . " - " . $ranges[$i]['max'] . " (" . count($range_values[$i]) . ")" . "<br />";
}
[] 300 - 699 (5)
[] 700 - 999 (2)
[] 1000 - 1500 (2)

Try
$intarray = array("300","350","399","650","625","738","983","1200","1050");
sort($intarray);
$result=array();
foreach($intarray as $key=>$val){
switch($val){
case ($val > 300 && $val < 699):
$result[0][] = $val;
break;
case ($val > 700 && $val < 999):
$result[1][] = $val;
break;
case ($val > 1000 && $val < 1500):
$result[2][] = $val;
break;
}
}
demo here

You can do a function that prints and counts the numbers in your range
public function printInRanges($startRange, $endRange)
{
$count = 0;
foreach($element in $array)
{
if($element>=$startRange && $element<=$endRange)
count++;
}
echo $startRange."-".$endRange."(".$count.")";
}
And than you can call this function with whatever ranges you want
Last Edit
if you want to do this for all your array, get your first element value (array[0]) and last element value, and call the function from a loop
$startValue = array[0];
while($startValue + 500 < $endValue)// 500 being the value between ranges like 0-500,500-1000,1000-1500
{
printInRanges($startValue ,$startValue +500);
$startValue+=500;
}

Related

PHP find all combinations to a sum in inner array

I'm writing a PHP script for available rooms in a hotel. I want every combination for a group (i.e. 4 person). This is my array.
$room_array = array(
array(
"title" => "1 person room",
"room_for" => 1,
"price" => 79
),
array(
"title" => "2 person room with other",
"room_for" => 1,
"price" => 69
),
array(
"title" => "2 person room alone",
"room_for" => 1,
"price" => 89
),
array(
"title" => "2 person",
"room_for" => 2,
"price" => 69
),
array(
"title" => "3 person",
"room_for" => 3,
"price" => 69
)
);
Possible outcome:
4x 1 person room
4x 2 person room with other
3x 1 person room + 1x 2 person room with other
2x 2 person room
1x 3 person room + 1x 1 person room
etc. etc.
This calls for a recursive function. But every example I looked at doesn't work with counting in the inner array. The closest i found was this question:
Finding potential combinations of numbers for a sum (given a number set to select from)
But i didn't get de solution to work..
UPDATE:
Hi, thanks for all the answers. Really helped me in finding the best practice. In the meantime, the assignment has changed a little so I can't answer my own original question. My problem is solved. Thanks again for the help!
My answer below will get you partway there.
Resources
I borrowed some code logic from this answer.
To quote the answer (in case of future removal), please view below.
You can try
echo "<pre>";
$sum = 12 ; //SUM
$array = array(6,1,3,11,2,5,12);
$list = array();
# Extract All Unique Conbinations
extractList($array, $list);
#Filter By SUM = $sum $list =
array_filter($list,function($var) use ($sum) { return(array_sum($var) == $sum);});
#Return Output
var_dump($list);
Output
array
0 => array
1 => string '1' (length=1)
2 => string '2' (length=1)
3 => string '3' (length=1)
4 => string '6' (length=1)
1 => array
1 => string '1' (length=1)
2 => string '5' (length=1)
3 => string '6' (length=1)
2 => array
1 => string '1' (length=1)
2 => string '11' (length=2)
3 => array
1 => string '12' (length=2)
Functions Used
function extractList($array, &$list, $temp = array()) {
if(count($temp) > 0 && ! in_array($temp, $list))
$list[] = $temp;
for($i = 0; $i < sizeof($array); $i ++) {
$copy = $array;
$elem = array_splice($copy, $i, 1);
if (sizeof($copy) > 0) {
$add = array_merge($temp, array($elem[0]));
sort($add);
extractList($copy, $list, $add);
} else {
$add = array_merge($temp, array($elem[0]));
sort($add);
if (! in_array($temp, $list)) {
$list[] = $add;
}
}
}
}
My answer
The code below uses the code referenced above. I changed the return functionality of the array_filter function to map it to your needs.
The only thing left for you to do is change the function so that it can catch multiple of the same type of room. At the moment, the code below will only output 1 of each type of room (as per the code referenced above). An easy way to get around this would be to multiply the array values you send to the function by the number of guests you are searching for rooms, but up to the amount of rooms available. So: if you are looking to book for 4 guests and you have no single rooms remaining and only 1 double room, your best match result would have to be a 2 person room and a 3 person room. I've added some brief functionality to add this (it's commented out), although I have not tested it. It will likely take a while to process that as well so if you're looking for a quicker method, you're gonna have to use a better algorithm as already mentioned in previous comments/answers or solve P vs NP
The code below also gives you the option to toggle a value of $exact. This value, if set to true, will return only matches exactly equal to the number of guests, and if set to false will return all matches that equal to at least the number of guests.
<?php
class Booking {
private $minGuests = 1;
protected $guests = 1;
protected $rooms = [];
public function getRoomCombinations(bool $exact = true) {
$guests = $this->guests;
$list = [];
$rooms = $this->rooms;
/*for($i = 0; $i < $guests-1; $i++) {
$rooms = array_merge($rooms, $this->rooms);
}
asort($rooms);*/
$this->extractList($rooms, $list);
$result = array_filter($list, function($var) use ($guests, $exact) {
if($exact)
return(array_sum(array_map(function($item) { return $item['room_for'];}, $var)) == $guests);
else
return(array_sum(array_map(function($item) { return $item['room_for'];}, $var)) >= $guests && count($var) <= $guests);
});
array_multisort(array_map('count', $result), SORT_ASC, $result);
return $result;
}
private function extractList(array $array, array &$list, array $temp = []) {
if (count($temp) > 0 && !in_array($temp, $list))
$list[] = $temp;
for($i = 0; $i < sizeof($array); $i++) {
$copy = $array;
$elem = array_splice($copy, $i, 1);
if (sizeof($copy) > 0) {
$add = array_merge($temp, array($elem[0]));
sort($add);
$this->extractList($copy, $list, $add);
} else {
$add = array_merge($temp, array($elem[0]));
sort($add);
if (!in_array($temp, $list)) {
$list[] = $add;
}
}
}
}
public function setGuests(int $guests) {
$this->guests = ($guests >= $this->minGuests ? $guests : $this->minGuests);
return $this;
}
public function setHotelRooms(array $rooms) {
$this->rooms = $rooms;
return $this;
}
}
$booking = (new Booking())
->setGuests(4)
->setHotelRooms([
[
"title" => "1 person room",
"room_for" => 1,
"price" => 79
],
[
"title" => "2 person room with other",
"room_for" => 1,
"price" => 69
],
[
"title" => "2 person room alone",
"room_for" => 1,
"price" => 89
],
[
"title" => "2 person",
"room_for" => 2,
"price" => 69
],
[
"title" => "3 person",
"room_for" => 3,
"price" => 69
]
]);
echo '<pre>' . var_export($booking->getRoomCombinations(true), true) . '</pre>';
?>
If you need all the combinations then you can use an backtracking iterative algorithm (depth path).
In summary:
Type of tree: binary tree because all the levels can contain a solution when the number of persons contabilized = objetive
Binary tree
Algorithm functions
You need to increment the cont every time that a level is generated with the number of persons of the level and decrement when you change your track (exploring brothers or back)
solution: array[0..levels-1] values {0 (node not selected) ,1 (node selected)}
solution[0] = 1 -> You choose that "1 person room" belongs to the solution
solutions: list/array of objects and every object contains array of titles of rooms
function Backtracking ()
level:= 1
solution:= s_initial
end:= false
repeat
generate(level, solution)
IF solution(level, solution) then
save_solution
else if test(level, solution) then
level:= level+ 1
else
while NOT MoreBrothers(level, solution)
go_back(level, s)
until level==0
2.1. Generate: generate next node
2.2. Solution: test if it's a solution
2.3. Critery: if we must continue by this track or bound
2.4. MoreBrothers: if there are nodes without check at this level
2.5. Backtrack: all the nodes at this level were explored
2.6. Save solution: add to the solutions array your object that contains strings
$room_array = array(
array(
"title" => "1 person room",
"room_for" => 1,
"price" => 79
),
array(
"title" => "2 person room with other",
"room_for" => 1,
"price" => 69
),
array(
"title" => "2 person room alone",
"room_for" => 1,
"price" => 89
),
array(
"title" => "2 person",
"room_for" => 2,
"price" => 69
),
array(
"title" => "3 person",
"room_for" => 3,
"price" => 69
)
);
// Gets rooms based on a given number of guests
function get_possible_rooms($num_guests) {
global $room_array;
$possible_rooms = [];
foreach ($room_array as $room) {
if ($num_guests <= $room['room_for']) {
$possible_rooms[] = $room['title'];
}
}
return $possible_rooms;
}
// Gets the available room capacities
function get_room_capacities() {
global $room_array;
$capacities = [];
foreach ($room_array as $room) {
$capacities[] = $room['room_for'];
}
return array_unique($capacities);
}
// Gets the different combinations of groups of guests based on the room capacities
function get_guest_assignments($remaining_guests, $parent_id = '', $num_guests, &$result) {
$room_capacities = get_room_capacities();
for ($i = 1; $i <= $remaining_guests; ++$i) {
if (in_array($i, $room_capacities)) {
$parent_guests = (isset($result[$parent_id])) ? $result[$parent_id] : 0;
$result[$parent_id . $i] = $parent_guests + $i;
for ($j = 1; $j <= $remaining_guests - $i; ++$j) {
// Recursively get the results for children
get_guest_assignments($j, $parent_id . $i, $num_guests, $result);
}
}
}
if ($remaining_guests === 1 && $parent_id !== '') {
// If it reaches the end and it does not fulfill the required number of guests,
// mark it for removal later
if ($result[$parent_id] < $num_guests) {
$result[$parent_id] = null;
}
}
// This is the last recursion
if ($result[$parent_id . '1'] === $num_guests) {
// Remove duplicates.
// To do this, we need to re-sort the keys (e.g. 21 becomes 12) and call array_unique()
// I admit this is a bit sloppy implementation.
$combinations = [];
foreach ($result as $key => $value) {
if ($value !== null) {
$nums = str_split($key);
sort($nums);
$combinations[] = implode('', $nums);
}
}
$result = array_unique($combinations);
}
}
// Gets the rooms for each group of guest
function get_room_assignments($guest_str) {
$rooms = [];
for ($i = 0; $i < strlen($guest_str); ++$i) {
$num_guests = intval(substr($guest_str, $i, 1));
$rooms[] = get_possible_rooms($num_guests);
}
return $rooms;
}
//----------
// RUN
//----------
$guests = 4;
$result = [];
get_guest_assignments($guests, null, $guests, $result);
foreach ($result as $guest_combi) {
$assignments = get_room_assignments($guest_combi);
// Printing output
echo 'Guest Combination ' . $guest_combi . "\n";
echo json_encode($assignments, JSON_PRETTY_PRINT);
echo "\n\n";
}
The output will look something like this:
...
Guest Combination 13
[
[
"1 person room",
"2 person room with other",
"2 person room alone",
"2 person",
"3 person"
],
[
"3 person"
]
]
...
"Guest combination 13" means the 4 guests will be split into groups of 1 and 3 persons.
Output is an array of possible rooms for each group. So in the example, the group of 1 can book 1 person room, 2 person room with other, ... 3 person room. And the group of 3 can book 3 person room.
—
Other notes:
I know we hate global but doing this just for brevity. Feel free to modify.
There's a shorter way to code this, but this implementation makes it easier to debug since guest combinations are used as keys.

PHP - get min and max values of numbers with special difference to each other

I have a problem getting the min and max values from a row of numbers with a special difference of 1800 in it. For better understanding, I want to give you the following example:
array(0,1800,3600,5400,7200,12600,14400,16200,23400,25200);
The special difference for my row of numbers is 1800. When a number has an exactly difference of 1800 to the next number, they are numbers of the same row. If not, they are numbers of another row. So I need a function which will produce the following output for the array mentioned above:
Output 1: min value 0, max value 7200
Output 2: min value 12600, max value 16200
Output 3: min value 23400, max value 25200
I hope you understand my question. Sorry for my english and thanks in advance.
It's alway better to show some of the code you have tried so far.
However here is a very short code example I put together.
$lists = [];
$special = 1800;
$array = [0, 1800, 3600, 5400, 7200, 12600, 14400, 16200, 23400, 25200];
$currentList = [];
foreach ($array as $number) {
if (empty($currentList)) {
$currentList[] = $number;
} else {
$last =(end($currentList) + $special);
if ($number === $last) {
$currentList[] = $number;
} else {
$lists[] = $currentList;
$currentList = [$number];
}
}
}
$lists[] = $currentList;
var_dump($lists);
This will output the following array, which could be transformed in the output you want.
array (size=3) 0 =>
array (size=5)
0 => int 0
1 => int 1800
2 => int 3600
3 => int 5400
4 => int 7200 1 =>
array (size=3)
0 => int 12600
1 => int 14400
2 => int 16200 2 =>
array (size=2)
0 => int 23400
1 => int 25200
You can create a helper function to iterate your input and add the values to an array of rows
function getRows($input, $specialDifference) {
$rows = array();
$newRow = true;
for ($index = 0; $index < count($input); $index++) {
if ($newRow) {
$rows[] = array();
$newRow = false;
}
$rows[count($rows) - 1][]= $input[$index];
$newRow = ((count($input) > $index + 1) && ($input[$index + 1] - $input[$index] !== $specialDifference));
}
return $rows;
}

Creating key value pairs using next two iterations in a for loop (PHP)

I have an array of string values called $genderAge that looks like this when echoed:-
F, 0-4, 327607378
M, 0-4, 392700793
F, 15-24, 887438943
M, 15-24, 525132614
M, 25-34, 621410857
So for the above array, $ageRange[0] is "F". $ageRange[1] is "0-4", and so forth.
I want to separate it out into two arrays, $male_array and $female_array with key value pairs. The key should be age range and the value should be cost.
$male_array = [];
$female_array = [];
for ($i = 0; $i < count($genderAge); $i++) {
if ($genderAge[i] == 'M') {
$male_array[$genderAge[i+1]] = $genderAge[i+2];
}
elseif ($genderAge[i] == 'F') {
$female_array[$genderAge[i+1]] = $genderAge[i+2];
}
}
foreach($male_array as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
The above doesn't echo anything. I want it to echo this:
Key=0-4, Value=392700793
Key=15-25, Value=525132614
Key=25-34, Value=621410857
Your $genderAge should be an array of this kind so that you can perform storing of values in the separate variables and you can use it for further purpose.
Proposed Array:
$genderAge = array("F", "0-4", "327607378", "M", "0-4", "392700793", "F", "15-24", "887438943","M", "15-24", "525132614","M","25-34", "621410857");
For Loop Manipulation over the array in order to save the value.
Here you must use $i for increment operator with +1. You must not use the i along separately as you have used.
PHP Code:
<?php
$genderAge = array("F", "0-4", "327607378", "M", "0-4", "392700793", "F", "15-24", "887438943","M", "15-24", "525132614","M","25-34", "621410857");
$male_array = [];
$female_array = [];
for ($i = 0; $i < count($genderAge); $i++) {
if ($genderAge[$i] == 'M') {
$male_array[$genderAge[$i+1]] = $genderAge[$i+2];
}
elseif ($genderAge[$i] == 'F') {
$female_array[$genderAge[$i+1]] = $genderAge[$i+2];
}
}
echo 'M Values'.'<br>';
foreach($male_array as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
echo '<br>';
echo 'F Values'.'<br>';
foreach($female_array as $y=> $y_value) {
echo "Key=" . $y . ", Value=" . $y_value;
echo "<br>";
}
echo '<br>';
?>
Output:
M Values
Key=0-4, Value=392700793
Key=15-24, Value=525132614
Key=25-34, Value=621410857
F Values
Key=0-4, Value=327607378
Key=15-24, Value=887438943
If your array is constantly a combination of 3 pairs : Gender, Age range, Cost, you may want to increment of each 3 pairs in your loop. It will save you from errors relative to out of array indexes :
<?php
$GENDER_MALE = 'M';
$GENDER_FEMALE = 'F';
$genderAge = ['F', '0-4', '327607378', 'M', '0-4', '392700793', 'F', '15-24', '887438943', 'M', '15-24', '525132614', 'M', '25-34', '621410857'];
$male_array = [];
$female_array = [];
$size = count($genderAge);
# Format the male/female array
for( $i = 0; $i < $size; $i += 3 ) {
$gender = $genderAge[$i]; // M or F
$ageRange = $genderAge[$i + 1]; // 0-4, 14-18, ...
$cost = $genderAge[$i + 2]; // 897726, 10927, ...
if( $gender == $GENDER_MALE ) {
$male_array[$ageRange] = $cost;
}
else if( $gender == $GENDER_FEMALE ) {
$female_array[$ageRange] = $cost;
}
}
# Print the male/female formatted array
foreach( $male_array as $key => $value ) {
echo "Age range : $key - cost = $value <br />";
}
?>
Notice in the first for loop the use of $i += 3 which can be read as :
Loop every 3 items on my array
This way, you can apply your index + n relative to the pair you need ($i + 1 for the age range, and so on).
First, You may want to get all those key-value pairs including the Sex in an associative array, instead. Here's how that could be done using for(){} Loop:
<?php
$arr = array("F"," 0-4", "327607378",
"M", "0-4", "392700793",
"F", "15-24", "887438943",
"M", "15-24", "525132614",
"M", "25-34", "621410857");
$all = array();
for($a=0, $b=1, $c=2; $a <= (count($arr)-3); $a+=3, $b+=3, $c+=3){
$temp = array(
"sex" => $arr[$a],
"key" => $arr[$b],
"value" => $arr[$c]
);
$all[] = $temp;
}
var_dump($all);
The call to var_dump($all); yields:
array (size=5)
0 =>
array (size=3)
'sex' => string 'F' (length=1)
'key' => string ' 0-4' (length=4)
'value' => string '327607378' (length=9)
1 =>
array (size=3)
'sex' => string 'M' (length=1)
'key' => string '0-4' (length=3)
'value' => string '392700793' (length=9)
2 =>
array (size=3)
'sex' => string 'F' (length=1)
'key' => string '15-24' (length=5)
'value' => string '887438943' (length=9)
3 =>
array (size=3)
'sex' => string 'M' (length=1)
'key' => string '15-24' (length=5)
'value' => string '525132614' (length=9)
4 =>
array (size=3)
'sex' => string 'M' (length=1)
'key' => string '25-34' (length=5)
'value' => string '621410857' (length=9)
Now, to echo out some data, you can just do something like this:
<?php
foreach($all as $iKey=>$arrKv){
echo "sex : " . $arrKv["sex"] . "<br />" . PHP_EOL;
echo "Key : " . $arrKv["key"] . "<br />" . PHP_EOL;
echo "Value : " . $arrKv["value"] . "<br /><br />" . PHP_EOL;
}
The Compound Result of each of the echo() in the Loop above yields:
sex : F
Key : 0-4
Value : 327607378
sex : M
Key : 0-4
Value : 392700793
sex : F
Key : 15-24
Value : 887438943
sex : M
Key : 15-24
Value : 525132614
sex : M
Key : 25-34
Value : 621410857

Add a non-repeatable line inside a foreach/switch

I have this loop, which shows books based in a year:
foreach ($cases_result as $case) {
$i = $case->n_ano;
switch ($i) {
case $i >= 2013:
echo $case->book.'<br>';
break;
case $i <= 2012 && $i >= 2011:
echo $case->book.'<br>';
break;
case $i <= 2010 && $i >= 2009:
echo $case->book.'<br>';
break;
case $i <= 2008 && $i >= 2007:
echo $case->book.'<br>';
break;
}
}
Is possible to to add a non-repeatable line to separate each case?
I need to show the year, like so:
2013
- book 1
- book 2
2012
- book 3
- book 4
Here is an excerpt of the array:
array (size=22)
0 =>
object(stdClass)[14]
public 'book' => string 'book 1' (length=6)
public 'n_ano' => string '2013' (length=4)
1 =>
object(stdClass)[15]
public 'book' => string 'book 2' (length=6)
public 'n_ano' => string '2013' (length=4)
2 =>
object(stdClass)[16]
public 'book' => string 'book 3' (length=6)
public 'n_ano' => string '2012' (length=4)
This should work for you:
First I create an array, which uses the year as key and adds the book name to the array, so you then can simply loop over it, e.g.
<?php
foreach($arr as $v)
$data[$v->n_ano][] = $v->book;
foreach($data as $n_ano => $books) {
echo $n_ano . "<br>";
foreach($books as $book)
echo " - " . $book . "<br>";
}
?>
output:
2013
- book 1
- book 2
2012
- book 3
First, sort your array by n_ano. Then you can easily loop trough the sorted result and create a grouped output.
function sortCases($a, $b) {
return $a->n_ano < $b->n_ano;
}
usort($cases_result, "sortCases");
$out = '';
$i = 0;
foreach ($cases_result as $case) {
//If the year is different, print year and assign it so $i
if($i !== intval($case->n_ano)) {
$out .= '<h2>' . $case->n_ano . '</h2>';
$i = intval($case->n_ano);
}
$out .= $case->book . '<br>';
}
print $out;

CodeIgniter select dropdown box with for loop

I try to create loop for select box
for select time start 8.00 and increasing it continusly
for this matter i found solution from
creating a loop for time incremented by 15 minutes
but i put it into my code under array it shows only one time
but i use
var_dump($timeinoption)
it shows correctly
as
array (size=1)
'8 . 0' => string '8 . 0' (length=5)
array (size=1)
'8 . 15' => string '8 . 15' (length=6)
array (size=1)
'8 . 30' => string '8 . 30' (length=6)
array (size=1)
'8 . 45' => string '8 . 45' (length=6)
array (size=1)
'9 . 0' => string '9 . 0' (length=5
but codeignaiter select box not work;
form_dropdown('timein',$timeinoption,'8.30');
it shows only one time on select box
echo form_label('Time Start','timestart');
for ($i = 8; $i <= 17; $i++)
{
for ($j = 0; $j <= 45; $j+=15)
{
//inside the inner loop
$opti= $i.' . '. $j;
$timeinoption=array($opti=>$opti) ;
}
//inside the outer loop
}
echo form_dropdown('timein',$timeinoption,'8.30');
?>
You are overwriting your array on each loop
$timeinoption=array($opti=>$opti);
So there will only be 1 value in your array.
Try changing to
$timeinoption[$opti]= $opti;
You have to array inside the loop :
$timeinoption = array();
for ($i = 8; $i <= 17; $i++)
{
for ($j = 0; $j <= 45; $j+=15)
{
//inside the inner loop
$opti= $i.' . '. $j;
$timeinoption[$opti] = $opti;
}
//inside the outer loop
}
Easy Way to Put loop Dropdown in CI
$d_opt = array(0 => 'DD');
for($i=1;$i<=31;$i++)
{
if(strlen($i)<2)
{
$i = 0 . $i;
}
$d_opt[$i]=$i;
}
echo form_dropdown('date',$d_opt);

Categories