I have array with alphanumeric key values..While filling array on particular condition I have filled array key with empty
word. Now I want if on key empty
is arises array should be increment with one position, so that that value is not stored in db. Simply want to skip that key and move to next.
foreach( $inputs as $key => $value) {
if(key($inputs)=="empty"){ $inputs[]++; }
else{ echo "<strong>$key</strong> Singer <strong>$value</strong></br>";
//INSERT Query; }
}
For deleting elements for an array use:
unset($inputs[$key]);
For skipping, perhaps the most obvious is:
if(key($inputs) !== "empty") {
//..
}
Note: you can insert multiple rows with one query, it might be better to do that.. build an array containing the rows "(value1,value2,...)" and use implode
you perhaps mean to use something like a conditional continue
inside your foreach loop:
foreach( $inputs as $key => $value)
{
if ($key === "empty")
{
continue; # at next element in $inputs
}
echo "<strong>$key</strong> Singer <strong>$value</strong></br>";
//INSERT Query;
}
Not sure I understand what you want, but:
foreach( $inputs as $key => $value) {
if ($key == 'empty') continue;
// insert query
}
Use continue
;
Change this:
if(key($inputs)=="empty"){ $inputs[]++; }
To:
if(key($inputs)=="empty"){ continue; }
I think you want this:
foreach( $inputs as $key => $value) {
if($key == "empty"){
$inputs[$key]++;
}
else{
echo "<strong>$key</strong> Singer <strong>$value</strong></br>";
//INSERT Query;
}