说我有以下数组:
[True, True, True, True]
Run Code Online (Sandbox Code Playgroud)
如何切换此数组中每个元素的状态?
切换会给我:
[False, False, False, False]
Run Code Online (Sandbox Code Playgroud)
同样,如果我有:
[True, False, False, True]
Run Code Online (Sandbox Code Playgroud)
切换会给我:
[False, True, True, False]
Run Code Online (Sandbox Code Playgroud)
我知道在Python中切换布尔值最简单的方法是使用"not",我在stackexchange上找到了一些例子,但我不知道如果它在数组中如何处理它.
我有一个MySQL数据库,我正在动态填充网页.我正在构建一个MySQL查询,该查询获取存储在一个表中的一些产品,这些产品products随后可以在PHP页面上回显.在该表中的列id,product_name,price和description.我希望用户能够按字母顺序,按价格(低 - 高)等对产品进行排序,方法是单击页面上的相关链接.这是我到目前为止所写的:
// Run a SELECT query to get all the products stored in the database
// By default, if no sorting URL variable is fed into the page, then the SQL query becomes order by id.
// The first time you land on the index page as plain index.php, not index.php?=variable, this is the query that's used
$sql = mysqli_query($con,"SELECT * FROM products ORDER BY id DESC");
// …Run Code Online (Sandbox Code Playgroud)