1. I've started a massive SPAM purge, any accounts that have spammed are being removed, also for a short period new user signups are disallowed until the SPAM cleaning is finished.

PHP Basics-11 Easy Steps

Discussion in 'PHP' started by midlandi, Nov 18, 2007.

  1. Richen ji

    Richen ji Member

    Joined:
    Sep 15, 2014
    Messages:
    15
    Likes Received:
    40
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Leh ladakh
    Sandeep Hatria, Bedi and Naruka Kumar like this.
  2. Richen ji

    Richen ji Member

    Joined:
    Sep 15, 2014
    Messages:
    15
    Likes Received:
    40
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Leh ladakh
    Hi, everybody.....

    what can we change array keys case,,,,,,yes

    example---


    <?php

    $age=array("Peter"=>35,"Ben"=>37,"Joe"=>43);
    echo "<pre>";
    print_r(array_change_key_case($age,CASE_UPPER));

    ?>

    output:

    Array
    (
    [PETER] => 35
    [BEN] => 37
    [JOE] => 43
    )
    Sandeep Hatria, Bedi and Naruka Kumar like this.
  3. Naruka Kumar

    Naruka Kumar Member

    Joined:
    Sep 15, 2014
    Messages:
    13
    Likes Received:
    33
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Delhi
    Hi,

    can we chunk array?
    .
    .
    .
    yes




    example---

    <?php

    $cars=array("Volvo","BMW","Toyota","Honda","Mercedes","Opel");

    echo "<pre>";

    print_r(array_chunk($cars,4));

    ?>

    output:

    Array
    (
    [0] => Array
    (
    [0] => Volvo
    [1] => BMW
    [2] => Toyota
    [3] => Honda
    )

    [1] => Array
    (
    [0] => Mercedes
    [1] => Opel
    )

    )
    Sandeep Hatria, Bedi and Richen ji like this.
  4. Naruka Kumar

    Naruka Kumar Member

    Joined:
    Sep 15, 2014
    Messages:
    13
    Likes Received:
    33
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Delhi
    Hi,

    can we combine keys and values of array..

    exmple:

    <?
    $fname=array("Pawan","Sammo","Bhikam");

    $age=array("25","25","23");

    $c=array_combine($fname,$age);

    echo "<pre>";
    print_r($c);
    ?>

    output:

    Array
    (
    [Pawan] => 25
    [Sammo] => 25
    [Bhikam] => 23
    )
    Sandeep Hatria, Bedi and Richen ji like this.
  5. Bedi

    Bedi Member

    Joined:
    Sep 16, 2014
    Messages:
    15
    Likes Received:
    32
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Gurgaon
    Hi,
    What is use of static function?

    ans: If we use static function in this case we don't require creating object of that class in which we are using static function.
  6. Sandeep Hatria

    Sandeep Hatria Member

    Joined:
    Sep 15, 2014
    Messages:
    15
    Likes Received:
    26
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Gurgaon
    Hi,
    how can be design HTML form:
    ANS:


    <form method="POST">
    <table>
    <tr><td> Student Name </td><td><input type="text" name="sname" required value="" placeholder="input your name" /> </td></tr>
    <tr><td> E-Mail ID </td><td><input type="text" name="semail" required value="" placeholder="input your e-mail" /> </td></tr>
    <tr><td> Class </td><td><input type="text" name="sclass" required value="" placeholder="input your class" /> </td></tr>
    <tr><td> Section </td><td><input type="text" name="ssection" required value="" placeholder="input your section" /> </td></tr>
    <tr><td> Roll no </td><td><input type="text" name="srollno" required value="" placeholder="input your roll no" /> </td></tr>
    <tr><td> </td><td><input type="submit" name="submit" value="SUBMIT YOUR RECORD" /> </td></tr>
    </table>

    </form>
    Bedi, Naruka Kumar and Richen ji like this.
  7. Sandeep Hatria

    Sandeep Hatria Member

    Joined:
    Sep 15, 2014
    Messages:
    15
    Likes Received:
    26
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Gurgaon
    Hi,

    How can we use php to get the HTML form values:


    <?php


    if(isset($_POST['submit'])){

    $sname=$_POST['sname'];
    $semail=$_POST['semail'];
    $sclass=$_POST['sclass'];
    $ssection=$_POST['ssection'];
    $srollno=$_POST['srollno'];
    echo $sname,"<br>";
    echo $semail,"<br>";
    echo $sclass,"<br>";
    echo $ssection,"<br>";
    echo $srollno,"<br>";
    Bedi, Naruka Kumar and Richen ji like this.
  8. Richen ji

    Richen ji Member

    Joined:
    Sep 15, 2014
    Messages:
    15
    Likes Received:
    40
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Leh ladakh
    Hi,
    how can be create database connection :

    $conn= new mysqli("localhost","root","","project_new");
    if($conn->connect_errno){
    echo connect_error;
    }
    Sandeep Hatria, Bedi and Naruka Kumar like this.
  9. Richen ji

    Richen ji Member

    Joined:
    Sep 15, 2014
    Messages:
    15
    Likes Received:
    40
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Leh ladakh
    Hi,
    How can be insert values into databae :


    if($stmt=$conn->prepare('INSERT INTO user4 SET s_name=?,s_email=?,s_class=?,s_section=?,s_rollno=? ')){
    $stmt->bind_param('sssss',$sname,$semail,$sclass,$ssection,$srollno);
    $stmt->execute();
    }
    Sandeep Hatria, Bedi and Naruka Kumar like this.
  10. Richen ji

    Richen ji Member

    Joined:
    Sep 15, 2014
    Messages:
    15
    Likes Received:
    40
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Leh ladakh
    Hi,
    SQl select query:

    $query="SELECT*FROM user4 ORDER BY ID DESC";
    Sandeep Hatria, Bedi and Naruka Kumar like this.
  11. Richen ji

    Richen ji Member

    Joined:
    Sep 15, 2014
    Messages:
    15
    Likes Received:
    40
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Leh ladakh
    Hi,
    for fetching the selected values from database:
    $r=$stmt->fetch_array(MYSQLI_ASSOC);
    Sandeep Hatria, Bedi and Naruka Kumar like this.
  12. Naruka Kumar

    Naruka Kumar Member

    Joined:
    Sep 15, 2014
    Messages:
    13
    Likes Received:
    33
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Delhi



    okkkk,yhanks buddy...
    Sandeep Hatria and Bedi like this.
  13. Naruka Kumar

    Naruka Kumar Member

    Joined:
    Sep 15, 2014
    Messages:
    13
    Likes Received:
    33
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Delhi

    can we run the query like:


    mysql_query();
    Sandeep Hatria and Bedi like this.
  14. Bedi

    Bedi Member

    Joined:
    Sep 16, 2014
    Messages:
    15
    Likes Received:
    32
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Gurgaon
    Hi,
    Can we Counts all the values of an array?

    yes

    example-
    <?
    $bedi=array(4,5,3,9,7,9,3,3,6);
    echo "<pre>";
    print_r(array_count_values($bedi));

    ?>

    output:

    Array
    (
    [4] => 1
    [5] => 1
    [3] => 3
    [9] => 2
    [7] => 1
    [6] => 1
    )
    Naruka Kumar and Sandeep Hatria like this.
  15. Bedi

    Bedi Member

    Joined:
    Sep 16, 2014
    Messages:
    15
    Likes Received:
    32
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Gurgaon
    Hi,

    can we Compare arrays, and returns the differences (compare values only)?

    yes.

    example--

    <?php
    $a1=array("a"=>"desire","b"=>"prompt","c"=>"real","d"=>"state");
    $a2=array("e"=>"desire","f"=>"prompt","g"=>"real");

    $result=array_diff($a1,$a2);
    echo "<pre>";
    print_r($result);
    ?>

    output:

    Array
    (
    [d] => state
    )
    Naruka Kumar and Sandeep Hatria like this.
  16. Sandeep Hatria

    Sandeep Hatria Member

    Joined:
    Sep 15, 2014
    Messages:
    15
    Likes Received:
    26
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Gurgaon
    Hi,

    can we Computes the difference of arrays with additional index check?

    yes.

    example--


    <?php
    $housing1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
    $housing2=array("a"=>"red","b"=>"green","c"=>"blue");

    $result=array_diff_assoc($housing1,$housing2);

    echo "<pre>";
    print_r($result);
    ?>

    output:

    Array
    (
    [d] => yellow
    )
    Naruka Kumar likes this.
  17. Sandeep Hatria

    Sandeep Hatria Member

    Joined:
    Sep 15, 2014
    Messages:
    15
    Likes Received:
    26
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Gurgaon
    Hi,
    can we Computes the difference of arrays using keys for comparison?

    yes.

    example--


    <?php
    $housing1=array("a"=>"red","b"=>"green","c"=>"blue");
    $housing2=array("a"=>"red","b"=>"green","d"=>"pink");

    $result=array_diff_key($housing1,$housing2);

    echo "<pre>";
    print_r($result);
    ?>

    output:

    Array
    (
    [c] => blue
    )
    Naruka Kumar likes this.
  18. Naruka Kumar

    Naruka Kumar Member

    Joined:
    Sep 15, 2014
    Messages:
    13
    Likes Received:
    33
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Delhi
    Hi,
    How can we Computes the difference of arrays with additional index check which is performed by a user supplied callback function?

    example--


    <?php
    function naruka($a,$b)
    {
    if ($a===$b)
    {
    return 0;
    }
    return ($a>$b)?1:-1;
    }

    $a1=array("a"=>"red","b"=>"green","c"=>"blue");
    $a2=array("d"=>"red","b"=>"green","c"=>"yellow");

    $result=array_diff_uassoc($a1,$a2,"naruka");
    echo "<pre>";
    print_r($result);
    ?>

    0utput:

    Array
    (
    [a] => red
    [c] => blue
    )
    aafgift likes this.
  19. Naruka Kumar

    Naruka Kumar Member

    Joined:
    Sep 15, 2014
    Messages:
    13
    Likes Received:
    33
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Delhi
    Hi,
    How can we Computes the difference of arrays using a callback function on the keys for comparison?

    example--

    <?php
    function naruka($a,$b)
    {
    if ($a===$b)
    {
    return 0;
    }
    else{
    return ($a>$b)?1:-1;
    }

    }

    $a1=array("a"=>"red","b"=>"green","c"=>"blue");
    $a2=array("a"=>"blue","b"=>"black","d"=>"blue");

    $result=array_diff_ukey($a1,$a2,"naruka");
    echo "<pre>";
    print_r($result);

    ?>

    output:

    Array
    (
    [c] => blue
    )
    aafgift likes this.
  20. aafgift

    aafgift New Member

    Joined:
    Sep 21, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Location:
    Dubai
    Hi,
    How can be Fill an array with values?

    example--



    <?php
    $aafgift1=array_fill(3,4,"polo shirt");
    $aafgift2=array_fill(0,1,"online shopping");

    echo "<pre>";
    print_r($aafgift1);
    echo "<br>";
    print_r($aafgift2);
    ?>

    output:
    Array
    (
    [3] => polo shirt
    [4] => polo shirt
    [5] => polo shirt
    [6] => polo shirt
    )

    Array
    (
    [0] => online shopping
    )

Share This Page