Since you're not using the key that each
provides, it isn't needed in this context.
As arrays are passed by-copy instead of by-reference, you can use array_shift()
as an alternative if you are not using $table_array
again in the same context.
foreach ($tables as $table_array) {
$table = array_shift($table_array);
var_dump($table);
}
Keep in mind array_shift retrieves the current value, and removes it from the array.
Since each()
retrieves the current key value pair and advances the pointer to the next value, you can replace it with current()
and next()
.
foreach ($tables as $table_array) {
$table = current($table_array);
var_dump($table);
next($table_array);
}
If you do need the key
of the current value when using current
and next
you can use key()
foreach ($tables as $table_array) {
$key = key($table_array);
$table = current($table_array);
var_dump($key, $table);
next($table_array);
}
Since the auto backup script you are using utilizes PDO, you can reduce the complexity by using fetchAll(PDO::FETCH_COLUMN);
instead of executeGetRows
Which will retrieve a flat array of the 0 indexed column as opposed to the column key value pair.
$result = $dbc->prepare("show tables");
$result->execute();
$i=0;
$table="";
$tables = $result->fetchAll(\PDO::FETCH_COLUMN);
foreach ($tables as $table) {
//...
}