是什么让这两个阵列添加不同

是什么让这两个阵列添加不同

本文介绍了是什么让这两个阵列添加不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我用这把用户的输入,并清理code。我试图解决这个问题了,然后​​code停止工作。

本作品:

  $ BindVar [] =阵列();
    $ BindVar [] = $电子邮件;
    $ BindVar [] = $通过;

然而,这并不:

  $ BindVar [] =阵列($电子邮件,$通行证);

下面是code当我改变该行打破:

 的foreach($ BindVars为$值){
        $输入[] ='。 $ mysqli-> real_escape_string($值)。 '; //清理输入
    }

它给出​​了这个错误:

解决方案

To understand your error message, I think it needs some explaination about Arrays.

If you use brackets like $bindVars[], you don't need to say, that it's an array by calling the array() function.

PHP understands the brackets [] as array declaration.


Your declarations with brackets [] and the array() function

$BindVars[] = array($Email,$pass);

// same as:
$BindVars = array(
    array($Email, $pass);
);

creates a new Array inside $bindVars containing the elements $Email & $pass.

So, $bindVars is already an Array because of the brackets []. That gives us a Multi-dimensional Array.

In your code, it's a 2-Dimensional Array, which represents a table. It's the most frequently used Multi-Dimensional Array.

A 3-Dimensional Array like $bindVars[][][] (3 pairs of brackets) represents a cube or a die.

A 4-Dimenisional Array $bindVars[][][][] (4 pairs of brackets) is then a cube with another dimension on each side of it. --- With every further Dimension it gets more mind-boggling ---

Back to the 2-Dimensional Array:

The 1. Dimension is the row or record

The 2. Dimension is the column or field.

// 1. Dimension: 1. row
echo $bindVars[0]; // Output: Array() Here is your mysqli error coming from!
/* --- 1. Record/Row --- */
// 2. Dimension: 1. row, 1. column
echo $bindVars[0][0]; // Output: value of $Email
// 2. Dimension: 1. row, 2. column
echo $bindVars[0][1]; // Output: value of $pass

 /* --- 2. Record/Row --- */
// 1. column
echo $bindVars[1][0]; // Output: value of $Email
// 2. column
echo $bindVars[1][1]; // Output: value of $pass

// And so on

Change

$BindVar[] = array($Email,$pass);

to

$BindVar = array($Email,$pass);

这篇关于是什么让这两个阵列添加不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 09:22