php - My While loop is not working, why? -
i have question in relationship loops in php. trying play actions elements of array, last one. need:
1- know array not empty.
2- pickup last item name of array. because need execute step0.php script.
3- delete last item of array.
i want repeat action until value of array 0 , go out loop.
i tried had not lucky. :-(
any idea?
$array2; $array1; $diffe_array = array_diff($array2, $array1); //create condiction $diffe=count($diffe_array); { $lastone=end($diffe_array); require('./step0.php'); $extract=array_pop($diffe_array); $diffe=count($diffe_array); print_r($diffe_array); } while ($diffe > 0); echo 'just have 0 items in array!!!!';
to complete question think necessary have clear (with example):
step1.- have $array2 this:
array2 ( [0] => 00004.csv [1] => 00007.csv [2] => 00005.csv [3] => 00003.csv [4] => 00002.csv [5] => 00001.csv [6] => 00006.csv [7] => 00000.csv )
step2.- have &array1 this:
array1 ( [0] => 00004.csv [1] => 00003.csv [2] => 00002.csv [3] => 00001.csv [4] => 00000.csv )
step3.- calculate diffe_array array_diff($array2,$array1):
diffe_array ( [1] => 00007.csv [2] => 00005.csv [6] => 00006.csv )
step4.- need create loop extract each item diffe_array , use in other script step0.php (this script open file same name of last item in diffe_array , share info database). need until diffe_array empty, goes out form loop.
by way, content of step0.php is:
<?php function conection() { if (!($link=pg_connect("host=xxxxx port=xxxx dbname=xxxxx user=xxxxx password=xxxxx"))) { echo "error connecting database."; exit(); } return $link; } require_once('./process.php');//this before file $rute="/rute/to/my/file/"; $end= $rute.$lastone; $row = 0; $handle = fopen($end, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== false) { $num = count($data); $row++; echo '<b><br/><br/>'; $request = "insert table(column1,column2,column3,column4) values("; ($c=0; $c < $num; $c++) { if ($c==($num-1)) $request = $request."'".$data[$c] . "'"; else $request = $request."'".$data[$c] . "',"; } $request = $request.");"; echo $request."<br>"; $union=conection(); $result=pg_query($union, $request); pg_close($union); } fclose($handle); ?>
first of - following code - $array1
, $array2
have no values, suppose array_diff()
function return error.
second, code, you'll going include step0.php
@ every loop. isn't approach.
last point: why use count()
every time, if know count before enter loop , pop 1 element? isn't better decrement $diffe
variable?
Comments
Post a Comment