TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-27-2009, 06:56 PM   #1 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 20
Thanks: 2
tech is on a distinguished road
Default some problem in array_search and the use of unset

dear friend..
php Code:
<?php
$x=array("r","a","f","c","s");

shuffle($x);

$z=array_search("c",$x);
unset($x[$z]);
print_r($x);
?>
PHP Code:
/*when i try to execute this code its working perfect.You need to notice one point in the output while removing the element-*/

Array
(
    [
0] => s
    
[1] => a
    
[2] => r
    
[4] => f


    [
0] => s
    
[1] => a
    
[2] => r
    
[3]=> Nothing here
    
[4] => f

/*You see that there is no index-3 in the array. Not acceptable. You have done great work.so now i wanted to use this function*/

array_remove_value($arr$value){
return 
array_diff($arr, array($value));
}

/*but i am unable to use it in my code..please help me how to use it.here is my code*/ 
php Code:
<?php
function extract1($this)
{
//if i have a parent

    if($this->parent)
    {
        try
        {     //if i can be removed from parent's contents array;
        array_splice($parent->content,$this);// here is doubt.
            }
            catch(Exception $e)
            {
                }

         }
        $lastChild=$this->lastRecursiveChild();
        $nextElement =$lastChild->next;

        if($this->previous)
         {
        $this->previous->next=$nextElement;
     }
        if($nextElement)
         {
        $nextElement->previous=$this->previous;
     }
        $this->previous=null;
        $lastChild->next = Null;
        $this->parent = Null;
        if ($this->previousSibling)
    {
        $this->previousSibling->nextSibling = $this->nextSibling;
        }
    if ($this->nextSibling)
    {
        $this->nextSibling->previousSibling = $this->previousSibling;
    }
    $this->previousSibling = $this->nextSibling = Null;
        return $this;
}
?>
please check try block.
thanks


Note added by: Codefreak, please format your code,
Prettifying Pasted Code on TalkPHP

Last edited by codefreek : 06-28-2009 at 10:48 AM. Reason: PHP tags added - please read http://www.talkphp.com/lounge/4563-prettifying-pasted-code-talkphp.html
tech is offline  
Reply With Quote
Old 06-27-2009, 08:10 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

I can't see in the second code where you are using your function array_remove_value.
Also what is the variable $parent coming from, maybe from $this->parent? (which by the way you can't use $this since it is a reserve word and its used public/private/protected methods of classes, can't use it to name parameters).

P.D. It would help if you edit the post and wrap the code snippets in PHP of CODE tags. it would be easier to read for everybody.
tony is offline  
Reply With Quote
Old 06-27-2009, 08:26 PM   #3 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 20
Thanks: 2
tech is on a distinguished road
Default

ya i haven't use array function bcoz i dont know how to use it.i'll tried with array_splice and unset but its not correct.the main thing I am facing to use this function.
one problem of using unset what i explained ...please check my try and catchwhere i used array_splice which is not proper..so please tell me how "i" can be removed from parent content array.here "i" have a parent.or can we use array_remove to solve this problem...
tech is offline  
Reply With Quote
Old 06-27-2009, 09:29 PM   #4 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

array_splice is used to replace content and it doesn't throw an exception, so there is no need to put it on a try-catch block.

to delete an element (the value and the index too) you can use this:
PHP Code:
$arr = array('4''sdf''seoij''sodifj');

$arr array_values(array_diff($arr, array('sdf'))); 
so you can make it a function:
PHP Code:
function array_remove($arr$value){
    return 
array_values(array_diff($arr, array($value)));
}

//then you can use this function like this
$arr = array('4''sdf''seoij''sodifj');
$arr array_remove($arr'sdf');
print_r($arr);
/*
Array
(
    [0] => '4'
    [1] => 'soeij'
    [2] => 'sodifj'
)
*/ 
Now in the example you gave, you are trying to apply this function to an array that is part of an object. I don't know how to help you on that since I don't know how the class of that object is structured.
But I hope this helps.
tony is offline  
Reply With Quote
Old 06-27-2009, 09:59 PM   #5 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Please use php tags or highlight tags.
Thank you.
codefreek is offline  
Reply With Quote
Old 06-27-2009, 10:26 PM   #6 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
it doesn't throw an exception, so there is no need to put it on a try-catch block.
I believe I've told him this before, good to see the effort that went into typing it paid off!!

PHP Parse error: parse error,syntex error unexpected ',' expectingT_STRING in my code
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 06-28-2009, 03:51 AM   #7 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

PHP doesn't use exceptions as general error handling, however using the builtin ErrorException class you can turn that into reality, but only if PHP emits an error:
php Code:
<?php
/* This is the call back for set_error_handler */
function exception_error_handler($severity, $message, $file, $line )
{
    throw new ErrorException($message, 0, $severity, $file, $line);
}

/* Set the new error handler */
set_error_handler('exception_error_handler');

/* Trigger exception, because this function needs more than 0 parameters */
try
{
    min();
}
catch(ErrorException $e)
{
    switch($e->getSeverity())
    {
        case(E_WARNING):
        {
            printf('Warning: %s in %s on line %d', $e->getMessage(), $e->getFile(), $e->getLine());
        }
        break;
        /* ... same for other error levels thats catchable here ... */
    }
}
?>

and testing:
Code:
C:\> php test.php
Warning: min() expects at least 1 parameter, 0 given in C:\test.php on line 14
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Old 10-18-2012, 12:38 PM   #8 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default

Some conservatives have Coach Factory Outlet pushed that critique further, saying that Mr. Obama’s policies are too costly, often assist the wrong people Louis Vuitton Belts and could have the paradoxical effect of driving up college costs. The dispute turns not just on different Coach Factory Outlet assessments of how policies play out, but on differing philosophical views about the role of government. During Gucci Belts his time in office, Mr. Obama has sharply increased aid to low- and middle-income students, notably through the Pell Grant Coach Factory Outlet program, which grew from $14.6 billion given to 6 million students in 2008, to nearly $40 billion for Coach Factory Outlet almost 10 million students this year. His administration also made it easier to request aid, shortening the Coach Factory Online complex federal application and allowing people to transfer their financial information electronically from the Internal Coach Outlet Online Revenue Service database. But while many education experts laud his efforts, analysts of varying political Coach Outlet Online stripes have also questioned how much impact some of the president’s policies will have, noting that the prices Coach Online Outlet charged by colleges, and student borrowing, continue to climb.But behind the headlines about soaring costs, the Coach Factory Outlet Online reality is more complex and wildly uneven, because a growing number of students receive Coach Outlet Online financial aid, and only relatively high-income families pay those fast-rising sticker prices. Adjusted for Coach Factory Online inflation, the College Board calculates, the average net price changed little over the last decade at private Coach Factory Outlet schools, and rose only modestly at public ones.Defending federal spending, Arne Duncan, the secretary of Hermes Belts education, said that for more than 30 years, college prices had risen even when federal aid had not, leading him to believe Coach Factory Online there was zero correlation.
dashixiong is offline  
Reply With Quote
Old 10-22-2012, 08:38 AM   #9 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default Coach Outlet

You’ve relativelyCoach Outlet recently arrived in New Delhi after living in two of Asia’s other great cities,Coach Outlet Store Online Tokyo and Hong Kong, for several years. Do these cities feel like they’re part of the same continent? Yes, and no. In terms Coach Factory Onlineof infrastructure, they couldn’t be more different. Getting regularCoach Outlet power and water at my house in New Delhi is never a sure thing, even though Coach Purse Outlet OnlineI’m paying the same rent that I paid in Tokyo and almost the same electricity prices. Both Hong Kong and Tokyo are also crowded places,Coach Factory Outlet Online but both cities are incredibly well planned and efficiently run. Efficient is not a word I would use to describe my Coach Bags Outlet Onlineday-to-day life in New Delhi. On the other hand, one thing that I think Hong Kong and New Delhi have in common isCoach Handbags Outlet a shared sense of optimism — a feeling that the best is yet to come. That’s definitely not the feeling you get in Tokyo,Coach Outlet Online or in the U.S. when I go home. It’s a big part of what I find addictive about living and working in this part of the world. You feel like you’re watching the future unfold.
dashixiong is offline  
Reply With Quote
Old 01-29-2013, 11:41 AM   #10 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default

Organizers said Coach Outlet Online was opportune because the battle’s 150-year anniversary is in December, and Fredericksburg Coach Factory Outlet has been preparing to mark the sesquicentennial. in the new agreement is that Coach Outlet Online revolutionary councils from 14 Syrian provinces now each have a representative, though not all live Coach Online Outlet in Syria. The hope is that will bind the coalition to those inside the country. Perhaps Coach Bags Outlet the most important body the new group is expected to form is a Revolutionary Military Council Coach Factory Online to oversee the splintered fighting organizations and to funnel both lethal and nonlethal Coach Factory Outlet military aid to the rebels. It should unite units of the Free Syrian Army, various militias Coach Outlet Store Online and brigades in each city and large groups of defectors. Before the ink was even dry on the Coach Outlet Store final draft, negotiators hoped that it would bring them the antiaircraft missiles they crave to Coach Factory Stores take on the Syrian Air Force. The United States and Britain have offered only Coach Handbags Outlet nonmilitary aid to the uprising. A similar attempt by the Syrian National Council to Coach Factory Store supervise the military never jelled. Organizers said funding was too haphazard. Eventually foreign Coach Factory Online governments like Qatar and Saudi Arabia, which are financing and arming the rebels, found Coach Factory Online their own favorite factions to deal with. Foreign leaders notably including Secretary of State Coach Outlet Hillary Rodham Clinton urged this unification largely so they could coordinate their Coach Factory Outlet efforts and aid through a group of technocrats. Once it receives international recognition, the Coach Outlet Store Online coalition is supposed to establish a temporary Coach Outlet Online military never jelled.
dashixiong is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:23 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design