我正在從mysql查詢中獲取多維數組。有點我正在使用以下功能。但是我在里面使用了php eval()函數。排序:function array_sorter() { $sortstring = ''; $sortarray = func_get_arg( 0 ); $count = ( func_num_args() - 1 ) / 2; foreach ( $sortarray as $key => $row ) : for ( $i = 1; $i <= $count; $i++ ) { $str ="\$key" . $i . " = \"" . func_get_arg( $i * 2 - 1 ) . "\";"; $str = $str . "\$array" . $i . "[\$key] = \$row[\$key" . $i . "];"; $str = $str . "\$\$key" . $i . " = \$array" . $i . ";"; @eval( $str ); } endforeach; for ( $i = 1; $i <= $count; $i++ ) { $key1 = func_get_arg( $i * 2 - 1 ); $sortstring = $sortstring . "\$" . $key1 . ", " . func_get_arg( $i * 2 ) . ", "; } $sortstring = "array_multisort( " . $sortstring . "\$sortarray );"; eval( $sortstring ); return $sortarray;}用法:$this->tabelle = array_sorter( $table, 'Rank', 0 );大批:Array( [Club] => Club 1 [Number] => 4 [Win] => 4 [Draw] => 0 [Lost] => 0 [Pos_Points] => 8 [Neg_Points] => 0 [Pos_Goals] => 244 [Neg_Goals] => 194 [Diff_Points] => 8 [Diff_Goals] => 50 [Rank] => 1)Array( [Club] => Club 2 [Number] => 3 [Win] => 2 [Draw] => 1 [Lost] => 0 [Pos_Points] => 5 [Neg_Points] => 1 [Pos_Goals] => 173 [Neg_Goals] => 163 [Diff_Points] => 4 [Diff_Goals] => 10 [Rank] => 2)我是說該函數運行良好,但是我不知道使用eval()函數的安全性。有沒有一種方法可以使它正常工作,而無需使用eval()來降低安全風險并使用最佳實踐php編碼標準(PHP 7)。
- 1 回答
- 0 關注
- 142 瀏覽
添加回答
舉報
0/150
提交
取消