Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8790541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:41:06+00:00 2026-06-13T22:41:06+00:00

I have an array that is a object which I carry in session lifeFleetSelectedTrucksList

  • 0

I have an array that is a object which I carry in session lifeFleetSelectedTrucksList
I also have objects of class fleetUnit

class fleetUnit {
    public $idgps_unit = null;
    public $serial = null;
}

class lifeFleetSelectedTrucksList {
    public $arrayList = array();
}

$listOfTrucks = new lifeFleetSelectedTrucksList(); //this is the array that I carry in session
if (!isset($_SESSION['lifeFleetSelectedTrucksList'])) {
    $_SESSION['lifeFleetSelectedTrucksList'] == null; //null the session and add new list to it.
} else {
    $listOfTrucks = $_SESSION['lifeFleetSelectedTrucksList'];
}

I use this to remove element from array:

$listOfTrucks = removeElement($listOfTrucks, $serial);

And this is my function that removes the element and returns the array without the element:

function removeElement($listOfTrucks, $remove) {
    for ($i = 0; $i < count($listOfTrucks->arrayList); $i++) {
        $unit = new fleetUnit();
        $unit = $listOfTrucks->arrayList[$i];
        if ($unit->serial == $remove) {
            unset($listOfTrucks->arrayList[$i]);
            break;
        } elseif ($unit->serial == '') {
            unset($listOfTrucks->arrayList[$i]);
        }
    }
    return $listOfTrucks;
}

Well, it works- element gets removed, but I have array that has bunch of null vaues instead. How do I return the array that contains no null elements? Seems that I am not suing something right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:41:08+00:00Added an answer on June 13, 2026 at 10:41 pm

    I think what you mean is that the array keys are not continuous anymore. An array does not have “null values” in PHP, unless you set a value to null.

    $array = array('foo', 'bar', 'baz');
    // array(0 => 'foo', 1 => 'bar', 2 => 'baz');
    
    unset($array[1]);
    
    // array(0 => 'foo', 2 => 'baz');
    

    Two approaches to this:

    1. Loop over the array using foreach, not a “manual” for loop, then it won’t matter what the keys are.
    2. Reset the keys with array_values.

    Also, removing trucks from the list should really be a method of $listOfTrucks, like $listOfTrucks->remove($remove). You’re already using objects, use them to their full potential!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I was trying to remove objects from object array that I have and
I have an array that's already been instantiated in the objects class (a.k.a. prototype)
I have an Array nested withing an Object that's inside an Object which is
I have an array that contains @sign in the object. I can't access that
I have an array that looks like this: [ Object actions: Array[2] comments: Object
I have been trying to assign value to an object array that is defined
I have an object that contains a array. On initialization of this object, the
I have a json object that looks something like this: Array ( [algorithm] =>
I have a custom object that I was adding to an array via a
I have an array an a timer that adds a new object to my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.