Jump to content

Search the Community

Showing results for tags 'php array'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 3 results

  1. I'm trying to unset one record from array but I can't manage it, so I'm asking for someone to help me. Logic I'm trying to achieve is: User has an item with possible three categories, he posts a form and than I iterate over array and try to see if category3 matches, if not I go to category2, if not I go to category1. If I find one of the categories that matches array and category asked in form I proceed , but If I don't find any of the categories I unset that record in array.Below you will see an example what I've done now. I can't get the proper result. Either I unset all the records or unset the record that should stay. I'm trying different conditions for last three days without success. Record I'm talking about is with a key 5. This is my array: array (size=5) 0 => array (size=9) 'cost_no' => string 'D01' (length=3) 'cost_name' => string 'Carina' (length=6) 'cost_type' => string 'Customs' (length=7) 'cost_measure' => string 'Percent' (length=7) 'cost_amount' => string '5.00' (length=4) 'cost_id' => int 7 'group1' => string '' (length=3) 'group2' => string '' (length=3) 'group3' => string '' (length=3) 1 => array (size=9) 'cost_no' => string 'D02' (length=3) 'cost_name' => string 'Banka' (length=5) 'cost_type' => string 'Bank' (length=4) 'cost_measure' => string 'Percent' (length=7) 'cost_amount' => string '0.15' (length=4) 'cost_id' => int 8 'group1' => string '' (length=3) 'group2' => string '' (length=3) 'group3' => string '' (length=3) 2 => array (size=9) 'cost_no' => string 'D03' (length=3) 'cost_name' => string 'Špediter' (length=9) 'cost_type' => string 'Transport' (length=9) 'cost_measure' => string 'Percent' (length=7) 'cost_amount' => string '0.50' (length=4) 'cost_id' => int 9 'group1' => string '' (length=3) 'group2' => string '' (length=3) 'group3' => string '' (length=3) 3 => array (size=9) 'cost_no' => string 'D04' (length=3) 'cost_name' => string 'Troškovi firme' (length=15) 'cost_type' => string 'Tax' (length=3) 'cost_measure' => string 'Percent' (length=7) 'cost_amount' => string '21.00' (length=5) 'cost_id' => int 10 'group1' => string '' (length=3) 'group2' => string '' (length=3) 'group3' => string '' (length=3) 5 => array (size=9) 'cost_no' => string 'C1' (length=2) 'cost_name' => string 'Cost only for this group' (length=24) 'cost_type' => string 'Warehouse' (length=9) 'cost_measure' => string 'Percent' (length=7) 'cost_amount' => string '12.00' (length=5) 'cost_id' => int 12 'group1' => string 'ACC_P' (length=5) 'group2' => string '1401' (length=4) 'group3' => string '' (length=3) This is foreach and condition I tried to use to unset if non of the categories match ( it has to check from category3 to category 1). foreach ($cost_array as $key1 => $value1) { if (isset($form_group3) AND isset($value1['group3']) AND $value1['group3'] != $form_group3) { if (isset($form_group2) AND isset($value1['group2']) AND $value1['group2'] != $form_group2) { if (isset($form_group1) AND isset($value1['group1']) AND $value1['group1'] != $form_group1) { } else { unset($cost_array[$key1]); } } else { unset($cost_array[$key1]); } } else { unset($cost_array[$key1]); } } Groups user posts from form: $form_group1 = mysqli_real_escape_string($conn_mysqli, $_POST['group1']); $form_group2 = mysqli_real_escape_string($conn_mysqli, $_POST['group2']); $form_group3 = mysqli_real_escape_string($conn_mysqli, $_POST['group3']); The result I need to achieve is that all records where empty group3,group2,group1 have to stay and the one which has records in group3, group2 or group1 has to stay only if they match what user asks. So if form_group3 is same is array_group3, form_group2 is same as array_group2, form_group1 is same as array_group1 that record stays otherwise only that one is unset.
  2. Hi All, I am using the below with great success. It finds for me the MIn and max values allong with the company names. The problem that has just presented itself is some of the data returned in the SLevel is text. I need to ignore text and only include numeric values. Is this possible. I have tried to work this out but have hit a brick wall. Many thanks Jon $SLevels = array(); foreach ($xml->Type->Company as $item) { $companyName = (string) $item->Name; // get the company name $tmp = (array) $item->$Level; if($tmp[0] != '-') $SLevels[] = array($tmp[0], $companyName); // add SLevel and company name to array } $minSLevel = min($SLevels); // get minimum value $minSLevel[0] = str_replace(',', '', $minSLevel[0]); $premium = $minSLevel[0]; $company = $minSLevel[1]; $maxSLevel = max($SLevels); // get minimum value $maxSLevel[0] = str_replace(',', '', $maxSLevel[0]); $maxpremium = $maxSLevel[0]; $maxcompany = $maxSLevel[1];
  3. hi mate, i have this json output and i need this to be in php array how can i do this, events : [ {'id':1, 'start': new Date(year, month, day, 12), 'end': new Date(year, month, day, 13, 00), 'title': 'Lunch with Sarah', userId: [1, 2]}, {'id':2, 'start': new Date(year, month, day, 14), 'end': new Date(year, month, day, 14, 40), 'title': 'Team Meeting', userId: 0}, ], free: [ {'start': new Date(year, month, day-1, , 'end': new Date(year, month, day-1, 18), 'free': true, userId: [0,1,2,3]}, {'start': new Date(year, month, day, , 'end': new Date(year, month, day+0, 18), 'free': true, userId: [0,1,2,3]}, ] Thanks in advance
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.