0

我实际上我想通过将查询划分为关键字将用户以前的搜索作为二维数组存储到会话中

<?php
session_start();

//weather searched or not
if(isset($_SESSION['searchedquery']))
{
    $string=$_SESSION['searchedquery'];
}
else
{
    $string="";
}

//when searched now query is made into key words



$encode = array(
    '/(\d+?)\.(\d+?)/' => '\\1DOT\\2',
    '/(\d+?),(\d+?)/' => '\\1COMMA\\2',
    '/(\d+?)-(\d+?)-(\d+?) (\d+?):(\d+?):(\d+?)/' => '\\1DASH\\2DASH\\3SPACE\\4COLON\\5COLON\\6'
);


foreach ($encode as $regex => $repl)
{
    $string = preg_replace($regex, $repl, $string);
}
preg_match_all('/\w+/', $string, $matches);
$decode = array(
                    'search' =>  array('DOT', 'COMMA', 'DASH', 'SPACE', 'COLON'),
                    'replace' => array('.',   ',',     '-',    ' ',     ':'    )
);
foreach ($matches as $k => $v)
{
    $matches[$k] = str_replace($decode['search'], $decode['replace'], $v);
}

//key words are obtained

// now session is maintained which captures the previus searches


/*
 number of previous searches done, here i'm saving a number of last
10 previous searches if this exceeds i'm using modulo operator to replace previous one by fifo/lifo ordeer
*/

if(!isset($_GET['searchednumber']))
{
    $_SESSION['searchednumber']=0;
}

// previous search value intialistalion //

/*from here actually i stucked , i want two dimentional array two keep track previous searched keywords */



if(!isset($_SESSION['searched']['values']))
{
    $values=Array("0","1","2","3","4","5","6","7","8","9","10");    // i'am unsure at this place
    $_SESSION['searched'][]=$values;            // i'am unsure at this place

}
$n=$_SESSION['searchednumber']; //total number of searches made

$p=$n%10;   // indices to store new query

if($n<10)   //number of iteration to done ... used just below this in for loop..
{
    $k=$n;
}
else
{
    $k=10;
}

$result=$matches[0];

//now preparing present query values from ablve ...top..
print_r($result);

//for debugging process

//code where i'm getting stucked dont why...



for($i=0; $i<$k; $i++)
{

    $result = array_udiff($result, $_SESSION['searched']['values'], 'strcasecmp');
}

//i'm unsure at this place
//here i want to clear all the keywords wchich were previously searched and to store in any one array i.e only allowing new keywords ... */


/*
 now depending upon result obtained where impli logic goes
*/

//but its not working as i intended its getting like ... "resource id #67" something is getting printed .....

print_r($result);

//now storing present query values to into indices...

$_SESSION['searched'][$p]=$matches[0];

?>

我被困在这个地方。

4

1 回答 1

0

你的问题在

$_SESSION['searched']['values']

你在哪里做的

$_SESSION['searched'][]=$values;

所以它已被推送到数组中,并且有一个 int 作为键,而不是“值”。

于 2013-06-05T09:22:16.477 回答