Web Analytics Made Easy -
StatCounter arrays and requirements - CodingForum

Announcement

Collapse
No announcement yet.

arrays and requirements

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • arrays and requirements

    So I'm having a tough time with this one. I almost had it down, but something went wrong, and I'm not sure what it was.
    Anyway, I want to take two arrays, one known and one required and compare them to see if the requirements are met.
    Have something like:
    $knownarray = ("1:5","2:3","7:4","32:1");
    and require
    $requirearray = ("17:2","2:2","1:3");
    $requirearray2 = ("7:2","1:4");

    Now what I need to do is take my requirements and seperate them, and compare to the known array. Then if all conditions are met, I want it to return an id for it, for later use. So with the above requirements, the numbers are seperated by the colon for the requiring id as well as the requiring number. The first example I want to be able to discard since the 17:2 is not found or met in the known, while the others are both found, and both with lower requiring numbers than whats known. The second would go through since all requirements are met. Heres what I currently have:
    PHP Code:
    $getall $DB_site->query("SELECT * FROM $table");
        while(
    $listall $DB_site->fetch_array($getall)){
            if (!
    $listall[requirement]){
        
    $genids .= "$listall[id], ";
        }else{
        
    $requirearray explode(", "$listall[requirement]);
        for(
    $i=0$i<count($requirearray); $i++){
            
    $rqd explode(":"$requirearray[$i]);
            }
        
    $knownarray explode(", ",$knownarray);
        for(
    $j=0$j<count($knownarray); $j++){
            
    $hve explode(":"$val);
            if (
    $hve[0] == $rqd["0"]){
        if (
    strcmp($hve[1],$rqd[1])>='0'){
            
    $genids .= "$getjobs[id], ";
        }
                        }
                    }
                }
            }
    $genids substr($genids,0,strlen($genids)-2);
    return 
    $genids
    Any suggestions?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #2
    There are many array functions built in that you can use instead of taking all the data out and then doing your comparisons. That just makes for bloated code and unnecessary resource use.



    This function wil compare two arrays and return an array containing the elements that were in the first array and not in the second.
    Spookster
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment


    • #3
      Thank you spookster.
      A quick question though, will that allow me to strip what I don't need out of there as well? I mean, I only need the number that the original id is for, none of the numbers that are included in there. That I think is probably the reason why that won't work, though I do not recall trying it, I think that I disuaded the use of array_diff just for that reason.
      Perhaps I wasn't quite clear enough originally:
      I have an id, lets call it #1.
      If just a simple query:
      PHP Code:
            $getone mysql->query_first("SELECT * FROM $table WHERE id='$id'");
             if (!
      $getone[requirement]){
                   
      $getids .= "$getone[id], ";
             }else{
                
      blah blah blah
      I think thats enough to explain what I mean. Its not nessessarly an array with any of the values between the known and the required that I'm looking for, but the ID that is associated with the requirement. Do you know what I mean, I'm sure its tough to understand what I'm trying to say, because I'm having difficulty typing it as well. If you need info, I'll send you a copy of what I'm looking at doing.
      PHP Code:
      header('HTTP/1.1 420 Enhance Your Calm'); 
      Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

      Comment

      Working...
      X