gpt4 book ai didi

php - 导入到 sql 数据库后如何删除空数组?

转载 作者:行者123 更新时间:2023-11-29 16:08:56 24 4
gpt4 key购买 nike

嗨,我有一个文本文件,我在 php 中读取该文件并将其拆分为数组。之后我有很多数组,其中一些是空的。如何删除这些空数组以及如何导入mysql数据库中的数据?连接就在那里。

//$DatabaseHost = "localhost"; 
//$DatabaseUser = "xx";
//$DatabasePassword = "xxx";
//$Database = "xxxx";
//$Table = "xxxx";

//******** Datenbank Connect ********

//$DatabaseConnect = mysql_connect($DatabaseHost, $DatabaseUser, $DatabasePassword) or die ("Keine Verbindung zum Server");
//$DatabaseSelect = mysql_select_db($Database, $DatabaseConnect) or die ("Die Datenbank gibt es nicht");


$datei = file("daten/neuer0.txt");
foreach($datei AS $ausgabe)
{ $zerlegen = explode(",", $ausgabe); }

function multiexplode ($delimiters,$string) {

$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return $launch;
}
$text = $ausgabe;
{
$exploded = multiexplode(array(",",".","|",":","\"","\\",),$text);

print_r($exploded);

最佳答案

您可以使用 array_filter 和 array_unique 函数来避免空白值,例如,

$array = array("1" => "PHP code tester Sandbox Online",  
"foo" => "bar", 5 , 5 => 89009,
"case" => "Random Stuff: " . rand(100,999),
"PHP Version" => phpversion(),"bb"=>''
);

$get_final_dga_data=array_unique($array);
$get_final_dga_data=array_filter($get_final_dga_data);
print_r($get_final_dga_data);

关于php - 导入到 sql 数据库后如何删除空数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55456502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com