本文整理汇总了PHP中str2arr函数的典型用法代码示例。如果您正苦于以下问题:PHP str2arr函数的具体用法?PHP str2arr怎么用?PHP str2arr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str2arr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProducts
/**
* 该方法的返回值为一下格式
* $result => {
* ' headers'=> //提供列表的头
* ' rows'=> //列表的内容(当前商品的属性的自由组合)
* }
*
*
*当前商品的属性值的值自由组合的sql
* select concat(t0.id,'#',t1.id) as goods_attribute_ids,t0.value as value0,t1.value as value1 from
(select id,value from goods_attribute where goods_id = 16 and attribute_id =2) as t0,
(select id,value from goods_attribute where goods_id = 16 and attribute_id = 6) as t1
order by t0.id,t1.id
*
*/
public function getProducts($goods_id)
{
//>>1.准备headers的数据(当前商品的多值属性)
$headers = $this->getMultValueAttribute($goods_id);
//>>2.准备rows的数据
//>>2.1 拼装自由组合的sql
$sql = "select concat(";
$goods_attribute_ids = array();
//存放id
$values = array();
//存放值
$selects = array();
foreach ($headers as $k => $header) {
$goods_attribute_ids[] = "t{$k}.id";
$values[] = "t{$k}.value as value{$k}";
$selects[] = "(select id,value from goods_attribute where goods_id = {$goods_id} and attribute_id ={$header['id']}) as t{$k}";
}
$sql .= arr2str($goods_attribute_ids, ",'#',") . ' ) as goods_attribute_ids,';
$sql .= arr2str($values, ',') . ' from ';
$sql .= arr2str($selects, ',') . ' order by ';
$sql .= arr2str($goods_attribute_ids, ',');
//>>2.2 再执行查询
$rows = $this->query($sql);
foreach ($rows as &$row) {
//>>这两步保证下的在前面
$goods_attribute_ids = str2arr($row['goods_attribute_ids'], '#');
sort($goods_attribute_ids);
$row['goods_attribute_ids'] = arr2str($goods_attribute_ids, '#');
}
//>>2.3.准备当前商品对应的产品
$products = $this->where(array('goods_id' => $goods_id))->select();
$goods_attribute_ids = array_column($products, 'goods_attribute_ids');
$products = array_combine($goods_attribute_ids, $products);
return array('headers' => $headers, 'rows' => $rows, 'products' => $products);
}
示例2: getMultAttribute
/**
* 得到商品的多值属性,产品列表数据
* @param $goods_id
* @return array
*/
public function getMultAttribute($goods_id)
{
//查询当前商品的多值的name
$sql = "select DISTINCT a.name,ga.attribute_id from goods_attribute as ga join attribute as a on ga.attribute_id=a.id where ga.goods_id={$goods_id} and a.input_type=2 and a.attribute_type=2";
$head = $this->query($sql);
//查询当前商品的多值笛卡尔积组合
$rows = '';
if ($head) {
//拼凑sql
$table = '';
$field1 = '';
$field2 = '';
foreach ($head as $k => $v) {
$field1 .= "t{$k}.value as value{$k},";
$field2 .= "t{$k}.id,'#',";
$table .= "(select * from goods_attribute where goods_id={$goods_id} and attribute_id={$v['attribute_id']}) as t{$k},";
}
$sql = 'select concat(' . trim($field2, ',\'#\',') . ') as attribute_ids,' . trim($field1, ',') . ' from ' . trim($table, ',');
$rows = $this->query($sql);
//将结果中attribute_ids排序
foreach ($rows as &$row) {
$temp = str2arr($row['attribute_ids'], '#');
sort($temp);
//排序
$row['attribute_ids'] = arr2str($temp, '#');
}
unset($row);
}
return array('head' => $head, 'rows' => $rows);
}
示例3: redisToMysql
/**
* 定时任务,将redis中的点击次数更新到mysql中
*/
public function redisToMysql()
{
//>>1.连接上redis
$redis = getRedis();
//>>2.需要从redis中得到所有商品的浏览次数
$keys = $redis->keys('goods_view_times:*');
$values = $redis->mget($keys);
//>>3.将浏览次数保存到数据库表goods_click中
foreach ($keys as $i => $key) {
$goods_id = str2arr($key, ':')[1];
//从goods_view_times:10中取出商品的id
$view_times = $values[$i];
//对应的浏览次数
$row = M('GoodsClick')->where('goods_id=' . $goods_id)->find();
if ($row) {
//有则更新
M('GoodsClick')->where(array('goods_id' => $goods_id))->setInc('click_times', $view_times);
} else {
//无则生成
M('GoodsClick')->add(array('goods_id' => $goods_id, 'click_times' => $view_times));
}
}
//>>4.将redis中的键删除
$redis->del($keys);
}
示例4: upload
public function upload()
{
/* 返回标准数据 */
$return = array('status' => 1, 'info' => '上传成功', 'data' => '');
/* 获取当前分类附件配置信息 */
$default = C('ATTACHMENT_DEFAULT');
$category = get_category(I('get.category'));
/* 分类正确性检测 */
if (empty($category)) {
$return['status'] = 0;
$return['info'] = '没有指定分类或分类不正确;';
} else {
$config = $category['extend']['attachment'];
$config = empty($config) ? $default : array_merge($default, $config);
/* 检测并上传附件 */
if (in_array('2', str2arr($config['allow_type']))) {
$setting = C('ATTACHMENT_UPLOAD');
/* 调用文件上传组件上传文件 */
$File = M('File');
$info = $File->upload($_FILES, $setting, $config['driver'], $config['driver_config']);
/* 记录附件信息 */
if ($info) {
$return['data'] = think_encrypt(json_encode($info['attachment']));
} else {
$return['status'] = 0;
$return['info'] = $File->getError();
}
} else {
$return['info'] = '该分类不允许上传文件附件!';
$return['status'] = 0;
}
}
/* 返回JSON数据 */
$this->ajaxReturn($return);
}
示例5: documentSaveComplete
/**
* 文档保存成功后执行行为
* @param array $data 文档数据
* @param array $catecory 分类数据
*/
public function documentSaveComplete($param)
{
if (MODULE_NAME == 'Home') {
list($data, $category) = $param;
/* 附件默认配置项 */
$default = C('ATTACHMENT_DEFAULT');
/* 合并当前配置 */
$config = $category['extend']['attachment'];
$config = empty($config) ? $default : array_merge($default, $config);
$attach = I('post.attachment');
/* 该分类不允许上传附件 */
if (!$config['is_upload'] || !in_array($attach['type'], str2arr($config['allow_type']))) {
return;
}
switch ($attach['type']) {
case 1:
//外链
# code...
break;
case 2:
//文件
$info = json_decode(think_decrypt($attach['info']), true);
if (!empty($info)) {
$Attachment = D('Addons://Attachment/Attachment');
$Attachment->saveFile($info['name'], $info, $data['id']);
} else {
return;
//TODO:非法附件上传,可记录日志
}
break;
}
}
}
示例6: hanlderRow
private function hanlderRow(&$rows)
{
foreach ($rows as &$row) {
if (!empty($row['option_values'])) {
$row['option_values'] = str2arr($row['option_values'], "\r\n");
}
}
}
示例7: getListByGoodsTypeId
/**
* 根据goods_type_id,查询属性信息
* @param $goods_type_id
* @return mixed
*/
public function getListByGoodsTypeId($goods_type_id)
{
$rows = $this->where(array('goods_type_id' => $goods_type_id, 'status' => 1))->field('sort,intro,status', true)->select();
//将option_values变成数组
foreach ($rows as &$row) {
$row['option_values'] = str2arr($row['option_values']);
}
unset($row);
return $rows;
}
示例8: clear
public function clear()
{
if (IS_POST) {
$PATHs = $_REQUEST['delids'];
$arrPath = str2arr($PATHs, ',');
foreach ($arrPath as $path) {
//var_dump(delDirAndFile($path));
delDirAndFile($path);
}
$this->ajaxReturn(array("status" => 200, "message" => "缓存文件已清除"));
}
}
示例9: listMap
/**
* 设置where查询条件
* @param number $category 分类ID
* @param number $pos 推荐位
* @param integer $status 状态
* @return array 查询条件
*/
private function listMap($category, $status = '', $pos = null)
{
/* 设置状态 */
if ($status) {
$map = array('status' => $status);
}
/* 设置分类 */
if (!is_null($category)) {
if (is_numeric($category)) {
$map['category_id'] = $category;
} else {
$map['category_id'] = array('in', str2arr($category));
}
}
/* 设置推荐位 */
if (is_numeric($pos)) {
$map[] = "position & {$pos} = {$pos}";
}
return $map;
}
示例10: get_str2arr
function get_str2arr($str)
{
if ($str) {
$emp = str2arr($str, ';');
for ($i = 0; $i < count($emp); $i++) {
$emp_no[] = str2arr($emp[$i], '|')[1];
}
if ($emp_no) {
return $emp_no;
}
}
}
示例11: delchildcat
private function delchildcat($cid)
{
// 找出所有子栏目及自身
$strchild = $this->category_model->getOne('catid,arrchildid', array('catid' => $cid));
$arrchild = str2arr($strchild['arrchildid']);
// 判断子栏目或者自身下是否有文章
foreach ($arrchild as $c) {
if ($this->article_model->getOne('artid,catid', array('catid' => $c))) {
return $c;
} else {
continue;
}
}
$this->category_model->deleteOne("catid in(" . $strchild['arrchildid'] . ")");
return true;
}
示例12: check_document_position
/**
* 检查$pos(推荐位的值)是否包含指定推荐位$contain
* @param number $pos 推荐位的值
* @param number $contain 指定推荐位
* @return boolean true 包含 , false 不包含
* @author huajie <banhuajie@163.com>
*/
function check_document_position($pos = 0, $contain = 0)
{
if (empty($pos) || empty($contain)) {
return false;
}
$arr = str2arr($pos);
$count = count($arr);
if ($count !== 1) {
return in_array($contain, $arr);
} else {
//将两个参数进行按位与运算,不为0则表示$contain属于$pos
$res = $pos & $contain;
if ($res !== 0) {
return true;
} else {
return false;
}
}
}
示例13: strbin_ulong
$in = "{$in}{$in}";
echo "strbin_ulong(", $in, ") = ", strbin_ulong($in), "<BR>";
echo "<BR>";
/**********************************************************/
echo "*******************************<BR>";
echo "str2arr(\$string) : <BR>";
echo "*******************************<BR>";
/**********************************************************/
$in = "01000001";
echo "str2arr(", $in, ") = ", str2arr($in), "<BR>";
$in = "0100000v";
echo "str2arr(", $in, ") = ", str2arr($in), "<BR>";
$in = "";
echo "str2arr(", $in, ") = ", str2arr($in), "<BR>";
$in = "10000000000000000000000000000000";
echo "str2arr(", $in, ") = ", str2arr($in), "<BR>";
echo "<BR>";
/**********************************************************/
echo "*******************************<BR>";
echo "readbit_ulong(\$val,\$bit) : <BR>";
echo "*******************************<BR>";
/**********************************************************/
$in = "~U~U~";
$pos = "0";
echo "readbit_ulong(", $in, ",", $pos, ") = ", readbit_ulong($in, $pos), "<BR>";
$pos = "1";
echo "readbit_ulong(", $in, ",", $pos, ") = ", readbit_ulong($in, $pos), "<BR>";
$pos = "30";
echo "readbit_ulong(", $in, ",", $pos, ") = ", readbit_ulong($in, $pos), "<BR>";
$pos = "31";
echo "readbit_ulong(", $in, ",", $pos, ") = ", readbit_ulong($in, $pos), "<BR>";
示例14: email_list
/**
* 邮箱列表
* @param [uid] [用户ID]
* @param int $page 页数
* @param int $page_size 条数
* @param [folder=''] [error]
* @param [folder=0] [未读邮件]
* @param [folder=1] [收件箱]
* @param [folder=2] [发件箱]
* @param [folder=3] [草稿箱]
* @param [folder=4] [已删除]
* @param [folder=5] [垃圾邮件]
* @param [folder=6] [永久删除]
* @return [type] id [邮件ID]
* @return [type] folder [类型]
* @return [type] name [<标题>]
* @return [type] content [内容]
* @return [type] add_file [<附件>]
* @return [type] from [发送者]
* @return [type] reply_to [<接受者>]
* @return [type] cc [<抄送>]
* @return [type] read [<是否已读>]
* @return [type] user_id [<发送者ID>]
* @return [type] user_name [<发送者姓名>]
* @return [type] create_time [<description>]
* @return [type] update_time [<description>]
* @return [type] is_del [<是否删除>]
* @return [type] bcc [<密送>]
* @return [type] is_bcc [<是否密送>]
*/
public function email_list()
{
$emp_id = UID;
$folder = $_REQUEST['folder'];
$page = $_REQUEST['page'];
$page_size = $_REQUEST['page_size'];
$where = $this->search_email();
switch ($folder) {
case '1':
//收件箱
$where['folder'] = array('eq', 1);
$where['is_del'] = array('eq', 0);
break;
case '2':
//发件箱
$where['folder'] = array('eq', 2);
$where['is_del'] = array('eq', 0);
break;
case '3':
//草稿箱
$where['folder'] = array('eq', 3);
$where['is_del'] = array('eq', 0);
break;
case '4':
//已删除
$where['folder'] = array('eq', 4);
break;
case '5':
//垃圾邮件
$where['folder'] = array('eq', 5);
$where['is_del'] = array('eq', 0);
break;
case '6':
//永久删除
$where['is_del'] = array('eq', 1);
break;
case '0':
//未读邮件
$where['folder'] = array('eq', 1);
$where['read'] = array('eq', 0);
$where['is_del'] = array('eq', 0);
break;
default:
$where['is_del'] = array('eq', 0);
break;
}
$where['user_id'] = $emp_id;
$order = 'create_time desc';
$data = M("Mail")->where($where)->order($order)->select();
for ($i = 0; $i < count($data); $i++) {
$from[$i] = str2arr($data[$i]['from'], '|');
$data[$i]['from'] = $from[$i][0] ? $from[$i][0] : '';
$data[$i]['folder'] = $data[$i]['folder'] ?: '';
$data[$i]['mid'] = $data[$i]['mid'] ?: '';
$data[$i]['name'] = $data[$i]['name'] ?: '';
$data[$i]['content'] = $data[$i]['content'] ?: '';
$data[$i]['add_file'] = $data[$i]['add_file'] ?: '';
$data[$i]['read'] = $data[$i]['read'] ?: '';
$data[$i]['user_name'] = $data[$i]['user_name'] ?: '';
$data[$i]['create_time'] = $data[$i]['create_time'] ?: '';
$data[$i]['update_time'] = $data[$i]['update_time'] ?: '';
$data[$i]['is_bcc'] = $data[$i]['is_bcc'] ?: '';
}
$result = page($page, $page_size, $data);
if ($result) {
$this->result(1, '查询成功', $result);
} else {
$this->result(0, '没有数据', '');
}
}
示例15: hexString_2_booleanArray
function hexString_2_booleanArray($hex)
{
$len = strlen($hex);
$t = "0000000100100011010001010110011110001001101010111100110111101111";
$binString = "";
for ($i = 0; $i < $len; $i++) {
$binString .= substr($t, hexdec(substr($hex, $i, 1)) * 4, 4);
}
return str2arr($binString);
}