Saturday, October 22, 2016

School Session

<label>Session  </label>
                                    <select name="year" required class="form-control">
                                         <?php  for ($i=$start_year;$i<$end_year;$i++)
                                                {
                                                    $j=$i+1;
                                                    echo '<option value="'.$i."-".$j.'"';  if(date("Y")==$i) echo 'selected="selected"'; echo '>'.$i."-".$j.'</option>';
                                                }  ?>
                                        <?php echo isset($_POST['year']) ?
                                        '<option value="'.$_POST['year'].'" selected="selected">'.$_POST['year'].'</option>'  : ''; ?>                                              
                                    </select>

Tuesday, September 27, 2016

Best way to add/insert to array in php

<?php
$array = array();
for (
$x = 1; $x <= 100000; $x++)
{
    
$array[] = $x;
}
?>
takes 0.0622200965881 seconds

and

<?php
$array 
= array();
for (
$x = 1; $x <= 100000; $x++)
{
    
array_push($array, $x);
}
?>

takes 1.63195490837 seconds

so if your not making use of the return value of array_push() its better to use the $array[] way.

Hope this helps someone.

Best way to add/insert to array in php

<?php
$array = array();
for (
$x = 1; $x <= 100000; $x++)
{
    
$array[] = $x;
}
?>
takes 0.0622200965881 seconds

and

<?php
$array 
= array();
for (
$x = 1; $x <= 100000; $x++)
{
    
array_push($array, $x);
}
?>

takes 1.63195490837 seconds

so if your not making use of the return value of array_push() its better to use the $array[] way.

Hope this helps someone.

Total Pageviews