0
         $data_rows = array();
         $row = array(
                        0 => get_the_title(), //Post Title
                        1 => get_the_content(), //Post Content
                        2 => $image[0], //Post Featured Image
                        3 => get_the_date(), //Post Date
                        4 => get_the_author(), //Post Author
                        5 => $post_categories, //Post Category
                        6 => $post_tag, //Post Tags
                        7 => get_post_status(), //Post Status
                    );
          $data_rows[] = $row;

right now this array fetching three columns in the format like......

Title1 - Content1 - Image1 - Date1 - Author Name1 - Category1 - Tag1 - Status1

Now, i want to delete a single row data item "Title1", "Title2", "Title3" by using key[0], how to do that?

I used "unset()" also but it didn't help.

2 Answers 2

1

To remove the first element try this,

array_shift($array);

or

 $array = array_slice($array, 1);

or array_splice() refer to Jason Swan's post

If you want to remove multi first element, use array_map() and above mothods.

$result = array_map(function($v){return array_slice($v, 1);}, $multidimensionarray);
Sign up to request clarification or add additional context in comments.

2 Comments

"$multidimensionarray" indicating..?
your $data_rows
1

Have you tried using array_splice()?

Syntax: array_splice(array,start, (optional) length)

EDIT: A simple dirty way would be to iterate over the $data_rows array and check if the key matches the title. It might not be the most efficient way though.

for($i=count($data_rows) - 1; i >= 0; i--){
  if(strpos(key[0], $data_rows[i][0]) !== false){
    array_splice($data_rows[i], 0, 1);
  }
}

The reason for iterating backwards is when you splice something, and then move forward one element, you skip the element that would have been next.

7 Comments

yes , used that also. array_splice also removing only a single row "Title" . It is not removing "Title1" and "Title2"
@Mukiikumar What are you trying to remove? The title from each of the rows? Or the row based upon the title itself?
All the titles from each rows.
@Mukiikumar based upon the key[0]? So if key[0] is "Title1" you want to remove the Title element from the row with the title "Title1"? Or just remove every title that contains the key[0]?
Yes, every title that containing the key[0].
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.