Magento2 Customer Data – How to Get All Data Using Object Manager

customermagento2

How to get all customer data using object manager.

Actually, I have created root file and load customer data with specific id but I want to load all customer data not a specific customer id.

What i have tried

    <?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$storeManager = $obj->get('\Magento\Store\Model\StoreManagerInterface');

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        

$appState = $objectManager->get('\Magento\Framework\App\State');
$appState->setAreaCode('frontend');

$customerID = 10;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerObj = $objectManager->create('Magento\Customer\Model\Customer')
->load($customerID);
$customerEmail = $customerObj->getEmail();
print_r($customerEmail);
?>

It is working but i only can get data from specific customer id.so how to get customer data of all customer id.

Best Answer

<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$storeManager = $obj->get('\Magento\Store\Model\StoreManagerInterface');

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        

$appState = $objectManager->get('\Magento\Framework\App\State');
$appState->setAreaCode('frontend');

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerObj = $objectManager->create('Magento\Customer\Model\Customer')->getCollection();
foreach($customerObj as $customerObjdata )
{
    echo "<pre/>";
    print_r($customerObjdata ->getData());
}