除了删除我想要的所有数组元素?

编程入门 行业动态 更新时间:2024-10-17 12:22:56
本文介绍了除了删除我想要的所有数组元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有控制器,从HTML表单接受后的参数,它就会送他们到模型,将插入数组卡桑德拉数据库中。

I have controller that takes post parameters from HTML form, it will then send them to model that will insert the array into Cassandra database.

这是SQL注入攻击的证据,因为它是NoSQL的,但是我怕的是,用户可以直接模拟100K后的参数或只是添加一些我不需要,它会被插入到数据库中。我怎样才能确保只有我所需要的值将留在我的数组。

It is SQLInjection proof, because it's NoSQL, however what I'm afraid is that user can just simulate 100k post parameters or just add some that I don't need and it will be inserted into database. How can I make sure that only the values I need will stay in my array.

例如:

$post = ['parent_id', 'type', 'title', 'body', 'tags']; // Good $post = ['parent_id', 'type', 'title', 'body', 'tags', 'one', 'two', 'three'] // Bad

我如何确保我的阵列将取消设置所有不在的好的例子吗?

推荐答案

您正在寻找 array_intersect :

You are looking for array_intersect:

$good = ['parent_id', 'type', 'title', 'body', 'tags']; $post = ['parent_id', 'type', 'title', 'body', 'tags', 'one', 'two', 'three']; print_r(array_intersect($good, $post));

看到它在行动

See it in action.

当然这个具体的例子并没有多大意义,因为它可以在阵列的值的,但也有 array_intersect_key ,做相同的基于上的按键。

Of course this specific example does not make much sense because it works on array values, but there is also array_intersect_key that does the same based on keys.

更多推荐

除了删除我想要的所有数组元素?

本文发布于:2023-11-01 01:52:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547900.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   元素   我想要

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!